Scippy

GCG

Branch-and-Price & Column Generation for Everyone

decomp.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 decomp.c
30 * @brief generic methods for working with different decomposition structures
31 * @author Martin Bergner
32 * @author Michael Bastubbe
33 *
34 * Various methods to work with the decomp structure
35 *
36 */
37
38/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
39
40//#define SCIP_DEBUG
41
42#include "gcg/decomp.h"
43#include "gcg/gcg.h"
44#include "gcg/cons_decomp.h"
45#include "scip/scip.h"
46#include "gcg/struct_decomp.h"
47#include "gcg/scip_misc.h"
48#include "gcg/relax_gcg.h"
49
50
51#include <assert.h>
52
53typedef struct {
59
60#define ELEM_SWAP(a,b) { register SCIP_Real t=(a);(a)=(b);(b)=t; }
61
62static
63SCIP_Real quick_select_median(SCIP_Real arr[], int n)
64{
65 int low, high;
66 int median;
67
68 low = 0;
69 high = n - 1;
70 median = high / 2;
71
72 for( ;; )
73 {
74 int middle, ll, hh;
75 if( high <= low ) /* One element only */
76 return arr[median];
77
78 if( high == low + 1 ) /* Two elements only */
79 {
80 if( arr[low] > arr[high] )
81 ELEM_SWAP(arr[low], arr[high]);
82 return arr[median];
83 }
84
85 /* Find median of low, middle and high items; swap into position low */
86 middle = (low + high) / 2;
87 if( arr[middle] > arr[high] )
88 ELEM_SWAP(arr[middle], arr[high]);
89 if( arr[low] > arr[high] )
90 ELEM_SWAP(arr[low], arr[high]);
91 if( arr[middle] > arr[low] )
92 ELEM_SWAP(arr[middle], arr[low]);
93 /* Swap low item (now in position middle) into position (low+1) */
94 ELEM_SWAP(arr[middle], arr[(size_t) (low + 1)]);
95 /* Nibble from each end towards middle, swapping items when stuck */
96 ll = low + 1;
97 hh = high;
98 for( ;; )
99 {
100 do
101 ll++;
102 while( arr[low] > arr[ll] );
103 do
104 hh--;
105 while( arr[hh] > arr[low] );
106 if( hh < ll )
107 break;
108 ELEM_SWAP(arr[ll], arr[hh]);
109 }
110 /* Swap middle item (in position low) back into correct position */
111 ELEM_SWAP(arr[low], arr[hh]);
112
113 /* Re-set active partition */
114 if( hh <= median )
115 low = ll;
116 if( hh >= median )
117 high = hh - 1;
118 }
119}
120
121
122/** fill out subscipvars arrays from the information from vartoblock */
123static
125 GCG* gcg, /**< GCG data structure */
126 GCG_DECOMP* decomp, /**< decomposition data structure */
127 SCIP_HASHMAP* vartoblock, /**< variable to block hashmap */
128 int nblocks, /**< number of blocks */
129 SCIP_VAR** vars, /**< variable array */
130 int nvars, /**< number of variables */
131 SCIP_Bool* haslinking /**< returns whether there are linking variables */
132 )
133{
134 SCIP_VAR*** subscipvars;
135 int* nsubscipvars;
136
137 SCIP_VAR** linkingvars;
138 int nlinkingvars;
139 int nmastervars;
140 int i;
141 SCIP* scip;
142
143 assert(gcg != NULL);
144 assert(decomp != NULL);
145 assert(vartoblock != NULL);
146 assert(nblocks >= 0);
147 assert(vars != NULL);
148
150 nlinkingvars = 0;
151 nmastervars = 0;
152
153 *haslinking = FALSE;
154
155 if( nvars == 0 )
156 return SCIP_OKAY;
157
158 SCIP_CALL( SCIPallocBufferArray(scip, &linkingvars, nvars) );
159 SCIP_CALL( SCIPallocBufferArray(scip, &nsubscipvars, nblocks) );
160 SCIP_CALL( SCIPallocBufferArray(scip, &subscipvars, nblocks) );
161
162 for( i = 0; i < nblocks; ++i )
163 {
164 SCIP_CALL( SCIPallocBufferArray(scip, &subscipvars[i], nvars) ); /*lint !e866*/
165 nsubscipvars[i] = 0;
166 }
167
168 /* handle variables */
169 for( i = 0; i < nvars; ++i )
170 {
171 int block;
172 SCIP_VAR* var;
173
174 var = vars[i];
175 assert(var != NULL);
176 assert(SCIPvarIsActive(var));
177
178 if( !SCIPhashmapExists(vartoblock, var) )
179 block = nblocks+1;
180 else
181 {
182 block = (int)(size_t)SCIPhashmapGetImage(vartoblock, var); /*lint !e507*/
183 }
184
185 assert(block > 0 && block <= nblocks+2);
186
187 /* if variable belongs to a block */
188 if( block <= nblocks )
189 {
190 SCIPdebugMessage("var %s in block %d.\n", SCIPvarGetName(var), block-1);
191 subscipvars[block-1][nsubscipvars[block-1]] = var;
192 ++(nsubscipvars[block-1]);
193 }
194 else /* variable is linking or master*/
195 {
196 assert(block == nblocks+1 || block == nblocks+2 );
197
198 if( block == nblocks+2 )
199 SCIPdebugMessage("var %s is linking.\n", SCIPvarGetName(var));
200 else
201 {
202 SCIPdebugMessage("var %s is in master only.\n", SCIPvarGetName(var));
203 ++nmastervars;
204 }
205 linkingvars[nlinkingvars] = var;
206 ++nlinkingvars;
207 }
208 }
209
210 if( nlinkingvars > 0 )
211 {
212 SCIP_CALL( GCGdecompSetLinkingvars(gcg, decomp, linkingvars, nlinkingvars, 0, nmastervars) );
213 *haslinking = TRUE;
214 }
215
216 for( i = nblocks-1; i >= 0; --i )
217 {
218 if( nsubscipvars[i] == 0 )
219 {
220 SCIPfreeBufferArray(scip, &subscipvars[i]);
221 subscipvars[i] = NULL;
222 }
223 }
224 if( nblocks > 0 )
225 {
226 SCIP_CALL( GCGdecompSetSubscipvars(gcg, decomp, subscipvars, nsubscipvars) );
227 }
228 GCGdecompSetVartoblock(decomp, vartoblock);
229
230 for( i = nblocks-1; i >= 0; --i )
231 {
232 SCIPfreeBufferArrayNull(scip, &subscipvars[i]);
233 }
234
235 SCIPfreeBufferArray(scip, &subscipvars);
236 SCIPfreeBufferArray(scip, &nsubscipvars);
237 SCIPfreeBufferArray(scip, &linkingvars);
238
239 return SCIP_OKAY;
240}
241
242
243/** fill out subscipcons arrays from the information from constoblock */
244static
246 GCG* gcg, /**< GCG data structure */
247 GCG_DECOMP* decomp, /**< decomposition data structure */
248 SCIP_HASHMAP* constoblock, /**< constraint to block hashmap */
249 int nblocks, /**< number of blocks */
250 SCIP_CONS** conss, /**< constraint array */
251 int nconss, /**< number of constraints */
252 SCIP_Bool* haslinking /**< returns whether there are linking constraints */
253 )
254{
255 SCIP* scip;
256 SCIP_RETCODE retcode;
257
258 SCIP_CONS*** subscipconss;
259 int* nsubscipconss;
260
261 SCIP_CONS** linkingconss;
262 int nlinkingconss;
263 int i;
264 assert(gcg != NULL);
265 assert(decomp != NULL);
266 assert(constoblock != NULL);
267 assert(nblocks >= 0);
268 assert(conss != NULL);
269 assert(haslinking != NULL);
270
271 *haslinking = FALSE;
272 retcode = SCIP_OKAY;
273
275 GCGdecompSetConstoblock(decomp, constoblock);
276
277 if( nconss == 0 )
278 return retcode;
279
280 SCIP_CALL( SCIPallocBufferArray(scip, &linkingconss, nconss) );
281 SCIP_CALL( SCIPallocBufferArray(scip, &nsubscipconss, nblocks) );
282 SCIP_CALL( SCIPallocBufferArray(scip, &subscipconss, nblocks) );
283
284 for( i = 0; i < nblocks; ++i )
285 {
286 SCIP_CALL( SCIPallocBufferArray(scip, &subscipconss[i], nconss) ); /*lint !e866*/
287 nsubscipconss[i] = 0;
288 }
289
290 nlinkingconss = 0;
291
292 /* handle constraints */
293 for( i = 0; i < nconss; ++i )
294 {
295 int block;
296 SCIP_CONS* cons;
297 int nvars;
298 SCIP_Bool success;
299
300 cons = conss[i];
301 assert(cons != NULL);
302
303 if( !SCIPhashmapExists(decomp->constoblock, cons) )
304 {
305 block = nblocks+1;
306 SCIP_CALL( SCIPhashmapInsert(decomp->constoblock, cons, (void*) (size_t) block) );
307 }
308 else
309 {
310 block = (int)(size_t)SCIPhashmapGetImage(decomp->constoblock, cons); /*lint !e507*/
311 }
312
313 assert(block > 0 && block <= nblocks+1);
314
315 SCIP_CALL( SCIPgetConsNVars(scip, cons, &nvars, &success) );
316 assert(success);
317 if( nvars == 0 )
318 continue;
319
320 /* if constraint belongs to a block */
321 if( block <= nblocks )
322 {
323 SCIPdebugMessage("cons %s in block %d.\n", SCIPconsGetName(cons), block-1);
324 subscipconss[block-1][nsubscipconss[block-1]] = cons;
325 ++(nsubscipconss[block-1]);
326 }
327 else /* constraint is linking */
328 {
329 SCIPdebugMessage("cons %s is linking.\n", SCIPconsGetName(cons));
330 assert(block == nblocks+1);
331 linkingconss[nlinkingconss] = cons;
332 ++nlinkingconss;
333 }
334 }
335
336 if( nlinkingconss > 0 )
337 {
338 retcode = GCGdecompSetLinkingconss(gcg, decomp, linkingconss, nlinkingconss);
339 *haslinking = TRUE;
340 }
341 if( nblocks > 0 )
342 {
343 retcode = GCGdecompSetSubscipconss(gcg, decomp, subscipconss, nsubscipconss);
344 }
345
346 for( i = nblocks-1; i >= 0; --i )
347 {
348 SCIPfreeBufferArray(scip, &subscipconss[i]);
349 }
350
351 SCIPfreeBufferArray(scip, &subscipconss);
352 SCIPfreeBufferArray(scip, &nsubscipconss);
353 SCIPfreeBufferArray(scip, &linkingconss);
354
355 return retcode;
356}
357
358/** removes a variable from the linking variable array */
359static
361 GCG* gcg, /**< GCG data structure */
362 GCG_DECOMP* decomp, /**< decomposition data structure */
363 SCIP_VAR* var, /**< variable to remove */
364 SCIP_Bool* success /**< indicates whether the variable was successfully removed */
365 )
366{
367 SCIP* scip;
368 int v;
369 int linkingvarsize;
370 assert(gcg != NULL);
371 assert(decomp != NULL);
372 assert(var != NULL);
373 assert(success != NULL);
374
376 *success = FALSE;
377 linkingvarsize = decomp->nlinkingvars;
378
379 for( v = 0; v < decomp->nlinkingvars; ++v )
380 {
381 if( decomp->linkingvars[v] == var )
382 {
383 decomp->linkingvars[v] = decomp->linkingvars[decomp->nlinkingvars-1];
384 decomp->nlinkingvars -= 1;
385 *success = TRUE;
386 }
387 }
388
389 if( *success )
390 {
391 if( decomp->nlinkingvars == 0 )
392 {
394 if( GCGdecompGetNLinkingconss(decomp) == 0 )
395 {
397 }
398 else
399 {
401 }
402 }
403 else
404 {
405 int oldsize = SCIPcalcMemGrowSize(scip, linkingvarsize);
406 int newsize = SCIPcalcMemGrowSize(scip, decomp->nlinkingvars);
407 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &decomp->linkingvars, oldsize, newsize) );
408 }
409 }
410 return SCIP_OKAY;
411}
412
413/** for a given constraint, check which of its variables were previously determined to be copied directly to the master,
414 * and assign them to the block to which the constraint belongs
415 */
416static
418 GCG* gcg, /**< GCG data structure */
419 GCG_DECOMP* decomp, /**< decomposition data structure */
420 SCIP_CONS* cons, /**< constraint whose variables should be assigned to its block */
421 int block /**< block to which the constraint has been assigned */
422 )
423{
424 SCIP* scip;
425 SCIP_VAR** curvars;
426 int ncurvars;
427
428 SCIP_Bool success;
429 int v;
430
432 curvars = NULL;
433 ncurvars = 0;
434
435 SCIP_CALL( SCIPgetConsNVars(scip, cons, &ncurvars, &success) );
436 assert(success);
437 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
438 SCIP_CALL( SCIPgetConsVars(scip, cons, curvars, ncurvars, &success) );
439 assert(success);
440
441 for( v = 0; v < ncurvars; ++v )
442 {
443 SCIP_VAR* probvar = SCIPvarGetProbvar(curvars[v]);
444
445 if( SCIPvarGetStatus(probvar) == SCIP_VARSTATUS_FIXED )
446 continue;
447
448 assert(SCIPhashmapExists(decomp->vartoblock, probvar));
449 /* if variable is in master only, move to subproblem */
450 if( (int) (size_t) SCIPhashmapGetImage(decomp->vartoblock, probvar) == decomp->nblocks+1 ) /*lint !e507 */
451 {
452 int oldsize;
453 int newsize;
454 oldsize = SCIPcalcMemGrowSize(scip, decomp->nsubscipvars[block]);
455 newsize = SCIPcalcMemGrowSize(scip, decomp->nsubscipvars[block] + 1);
456 SCIP_CALL( SCIPhashmapSetImage(decomp->vartoblock, probvar, (void*) (size_t)(block+1)) );
457 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &decomp->subscipvars[block], oldsize, newsize) ) /*lint !e866 */;
458 decomp->subscipvars[block][decomp->nsubscipvars[block]] = probvar;
459 decomp->nsubscipvars[block] += 1;
460 SCIP_CALL( removeFromLinkingvars(gcg, decomp, probvar, &success) );
461 assert(success);
462 }
463 }
464
465 SCIPfreeBufferArrayNull(scip, &curvars);
466
467 return SCIP_OKAY;
468}
469
470
472 GCG_DECTYPE type
473 )
474{
475 const char * names[] = { "unknown", "arrowhead", "staircase", "diagonal", "bordered" };
476 return names[type];
477}
478
479/** initializes the decomposition to absolutely nothing */
481 GCG* gcg, /**< GCG data structure */
482 GCG_DECOMP** decdecomp /**< pointer to the decomposition data structure */
483 )
484{
485 SCIP* scip;
486 GCG_DECOMP* decomp;
487
488 int ncalls;
489
490 assert(gcg != NULL);
491 assert(decdecomp != NULL);
492
494 SCIP_CALL( SCIPallocMemory(scip, decdecomp) );
495 assert(*decdecomp != NULL);
496 decomp = *decdecomp;
497
498 decomp->type = GCG_DECTYPE_UNKNOWN;
499 decomp->constoblock = NULL;
500 decomp->vartoblock = NULL;
501 decomp->subscipvars = NULL;
502 decomp->subscipconss = NULL;
503 decomp->nsubscipconss = NULL;
504 decomp->nsubscipvars = NULL;
505 decomp->linkingconss = NULL;
506 decomp->nlinkingconss = 0;
507 decomp->linkingvars = NULL;
508 decomp->nlinkingvars = 0;
509 decomp->nfixedlinkingvars = 0;
510 decomp->stairlinkingvars = NULL;
511 decomp->nstairlinkingvars = NULL;
512 decomp->nblocks = 0;
514 decomp->consindex = NULL;
515 decomp->varindex = NULL;
516 decomp->detector = NULL;
517 decomp->nmastervars = 0;
518
519 decomp->detectorchain = NULL;
520 decomp->sizedetectorchain = 0;
521 decomp->detectorchainstring = NULL;
522 decomp->partialdecid = -1;
523 decomp->detectorclocktimes = NULL;
524 decomp->pctvarstoborder= NULL;
525 decomp->pctconsstoborder= NULL;
526 decomp->pctvarstoblock= NULL;
527 decomp->pctconsstoblock= NULL;
528 decomp->pctvarsfromopen= NULL;
529 decomp->pctconssfromopen= NULL;
530 decomp->nnewblocks= NULL;
531 decomp->maxwhitescore = -1.;
532
534
535 SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "ncalls of createdecompfrompartialdec: %d \n", ncalls);
536
537 return SCIP_OKAY;
538}
539
540/** frees the decdecomp structure */
542 GCG* gcg, /**< pointer to the GCG instance */
543 GCG_DECOMP** decdecomp /**< pointer to the decomposition data structure */
544 )
545{
546 SCIP* scip;
547 GCG_DECOMP* decomp;
548 int i;
549 int j;
550 int ncalls;
551
552 assert( gcg!= NULL );
553 assert( decdecomp != NULL);
555 decomp = *decdecomp;
556 assert(decomp != NULL);
557
558 for( i = 0; i < decomp->nblocks; ++i )
559 {
560 if( decomp->nsubscipvars != NULL )
561 {
562 for( j = 0; j < decomp->nsubscipvars[i]; ++j )
563 {
564 if( decomp->subscipvars[i][j] != NULL )
565 {
566 SCIP_CALL( SCIPreleaseVar(scip, &(decomp->subscipvars[i][j])) );
567 }
568 }
569
570 SCIPfreeBlockMemoryArrayNull(scip, &(decomp->subscipvars[i]), SCIPcalcMemGrowSize(scip, decomp->nsubscipvars[i])); /*lint !e866*/
571
572 }
573 if( decomp->nsubscipconss != NULL )
574 {
575 for( j = 0; j < decomp->nsubscipconss[i]; ++j )
576 {
577 if( decomp->subscipconss[i][j] != NULL )
578 {
579 SCIP_CALL( SCIPreleaseCons(scip, &(decomp->subscipconss[i][j])) );
580 }
581 }
582 SCIPfreeBlockMemoryArrayNull(scip, &decomp->subscipconss[i], SCIPcalcMemGrowSize(scip, decomp->nsubscipconss[i])); /*lint !e866*/
583 }
584 }
585
586 if( decomp->linkingvars != NULL )
587 {
588 for( i = 0; i < decomp->nlinkingvars; ++i )
589 {
590 if( decomp->linkingvars[i] != NULL )
591 {
592 if( decomp->linkingvars[i] != NULL )
593 {
594 SCIP_CALL( SCIPreleaseVar(scip, &(decomp->linkingvars[i])) );
595 }
596 }
597 }
598 }
599
600 if( decomp->stairlinkingvars != NULL )
601 for( i = 0; i < decomp->nblocks-1; ++i )
602 {
603 for( j = 0; j < decomp->nstairlinkingvars[i]; ++j )
604 {
605 if( decomp->stairlinkingvars[i][j] != NULL )
606 {
607 SCIP_CALL( SCIPreleaseVar(scip, &(decomp->stairlinkingvars[i][j])) );
608 }
609 }
611 }
612
613 /* free hashmaps if they are not NULL */
614 if( decomp->constoblock != NULL )
616 if( decomp->vartoblock != NULL )
617 SCIPhashmapFree(&decomp->vartoblock);
618 if( decomp->varindex != NULL )
619 SCIPhashmapFree(&decomp->varindex);
620 if( decomp->consindex != NULL )
621 SCIPhashmapFree(&decomp->consindex);
622
623 for( i = 0; i < decomp->nlinkingconss; ++i )
624 {
625 SCIP_CALL( SCIPreleaseCons(scip, &(decomp->linkingconss[i])) );
626 }
635 if( decomp->detectorchain != NULL )
636 {
647 }
648
649 SCIPfreeMemoryNull(scip, decdecomp);
650
652
653 SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "ncalls of createdecompfrompartialdec: %d \n", ncalls);
654
655 return SCIP_OKAY;
656}
657
658/** sets the type of the decomposition */
660 GCG_DECOMP* decomp, /**< decomposition data structure */
661 GCG_DECTYPE type /**< type of the decomposition */
662 )
663{
664 SCIP_Bool valid;
665
666 assert(decomp != NULL);
667
668 switch( type )
669 {
671 valid = decomp->nlinkingconss == 0 && decomp->linkingconss == NULL;
672 valid = valid && decomp->nlinkingvars == 0 && decomp->linkingvars == NULL;
673 break;
675 valid = TRUE;
676 break;
678 valid = FALSE;
679 break;
681 valid = decomp->nlinkingvars == 0 && decomp->linkingvars == NULL;
682 break;
684 valid = decomp->nlinkingconss == 0 && decomp->linkingconss == NULL;
685 break;
686 default:
687 valid = FALSE;
688 break;
689 }
690
691 if( !valid )
692 {
693 SCIPerrorMessage("The decomposition is not of the given type!\n");
694 return SCIP_INVALIDDATA;
695 }
696
697 decomp->type = type;
698
699 return SCIP_OKAY;
700}
701
702/** gets the type of the decomposition */
704 GCG_DECOMP* decomp /**< decomposition data structure */
705 )
706{
707 assert(decomp != NULL);
708
709 return decomp->type;
710}
711
712
714 GCG_DECOMP* decomp /**< decomposition data structure */
715 )
716{
717 assert(decomp != NULL);
718
719 return decomp->maxwhitescore;
720}
721
722
723/** sets the presolved flag for decomposition */
725 GCG_DECOMP* decomp, /**< decomposition data structure */
726 SCIP_Bool presolved /**< presolved flag for decomposition */
727 )
728{
729 assert(decomp != NULL);
730
731 decomp->presolved = presolved;
732}
733
734/** gets the presolved flag for decomposition */
736 GCG_DECOMP* decomp /**< decomposition data structure */
737 )
738{
739 assert(decomp != NULL);
740
741 return decomp->presolved;
742}
743
744/** sets the number of blocks for decomposition */
746 GCG_DECOMP* decomp, /**< decomposition data structure */
747 int nblocks /**< number of blocks for decomposition */
748 )
749{
750 assert(decomp != NULL);
751 assert(nblocks >= 0);
752
753 decomp->nblocks = nblocks;
754}
755
756/** gets the number of blocks for decomposition */
758 GCG_DECOMP* decomp /**< decomposition data structure */
759 )
760{
761 assert(decomp != NULL);
762
763 return decomp->nblocks;
764}
765
766/** copies the input subscipvars array to the given decomposition */
768 GCG* gcg, /**< GCG data structure */
769 GCG_DECOMP* decomp, /**< decomposition data structure */
770 SCIP_VAR*** subscipvars, /**< subscipvars array */
771 int* nsubscipvars /**< number of subscipvars per block */
772 )
773{
774 SCIP* scip;
775 SCIP_Bool valid;
776 int i;
777 int b;
778 assert(gcg != NULL);
779 assert(decomp != NULL);
780 assert(subscipvars != NULL);
781 assert(nsubscipvars != NULL);
782 assert(decomp->nblocks >= 0);
783
784 assert(decomp->subscipvars == NULL);
785 assert(decomp->nsubscipvars == NULL);
786
787 if( decomp->nblocks == 0 )
788 return SCIP_OKAY;
789
791 valid = TRUE;
792
795
796 assert(decomp->subscipvars != NULL);
797 assert(decomp->nsubscipvars != NULL);
798
799 BMSclearMemoryArray(decomp->subscipvars, decomp->nblocks);
800 BMSclearMemoryArray(decomp->nsubscipvars, decomp->nblocks);
801
802 for( b = 0; b < decomp->nblocks; ++b )
803 {
804 assert((subscipvars[b] == NULL) == (nsubscipvars[b] == 0));
805 decomp->nsubscipvars[b] = nsubscipvars[b];
806
807 if( nsubscipvars[b] < 0 )
808 {
809 SCIPerrorMessage("Number of variables per subproblem must be nonnegative.\n");
810 valid = FALSE;
811 }
812 else if( nsubscipvars[b] > 0 )
813 {
814 int size;
815 assert(subscipvars[b] != NULL);
816 size = SCIPcalcMemGrowSize(scip, nsubscipvars[b]);
817 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &decomp->subscipvars[b], size) ); /*lint !e866*/
818 BMScopyMemoryArray(decomp->subscipvars[b],subscipvars[b], nsubscipvars[b]); /*lint !e866*/
819
820 for( i = 0; i < nsubscipvars[b]; ++i )
821 {
822 SCIP_CALL( SCIPcaptureVar(scip, decomp->subscipvars[b][i]) );
823 }
824 }
825 }
826
827 if( !valid )
828 {
829 return SCIP_INVALIDDATA;
830 }
831
832
833 return SCIP_OKAY;
834}
835
836/** returns the subscipvars array of the given decomposition */
838 GCG_DECOMP* decomp /**< decomposition data structure */
839 )
840{
841 assert(decomp != NULL);
842
843 return decomp->subscipvars;
844}
845
846/** returns the nsubscipvars array of the given decomposition */
848 GCG_DECOMP* decomp /**< decomposition data structure */
849 )
850{
851 assert(decomp != NULL);
852
853 return decomp->nsubscipvars;
854}
855
856/** copies the input subscipconss array to the given decomposition */
858 GCG* gcg, /**< GCG data structure */
859 GCG_DECOMP* decomp, /**< decomposition data structure */
860 SCIP_CONS*** subscipconss, /**< subscipconss array */
861 int* nsubscipconss /**< number of subscipconss per block */
862 )
863{
864 SCIP* scip;
865 SCIP_Bool valid;
866 int i;
867 int b;
868 assert(gcg != NULL);
869 assert(decomp != NULL);
870 assert(subscipconss != NULL);
871 assert(nsubscipconss != NULL);
872
873 assert(decomp->nblocks >= 0);
874 assert(decomp->subscipconss == NULL);
875 assert(decomp->nsubscipconss == NULL);
876
877 valid = TRUE;
878
879 if( decomp->nblocks == 0)
880 return SCIP_OKAY;
881
885
886 assert(decomp->subscipconss != NULL);
887 assert(decomp->nsubscipconss != NULL);
888
889 BMSclearMemoryArray(decomp->subscipconss, decomp->nblocks);
890 BMSclearMemoryArray(decomp->nsubscipconss, decomp->nblocks);
891
892 for( b = 0; b < decomp->nblocks; ++b )
893 {
894 if( nsubscipconss[b] <= 0 || subscipconss[b] == NULL )
895 {
896 SCIPerrorMessage("Block %d is empty and thus invalid. Each block needs at least one constraint.\n", b);
897 valid = FALSE;
898 }
899
900 decomp->nsubscipconss[b] = nsubscipconss[b];
901
902 if( nsubscipconss[b] > 0 )
903 {
904 int size;
905
906 assert(subscipconss[b] != NULL);
907 size = SCIPcalcMemGrowSize(scip, nsubscipconss[b]);
908 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &decomp->subscipconss[b], size) ); /*lint !e866*/
909 BMScopyMemoryArray(decomp->subscipconss[b], subscipconss[b], nsubscipconss[b]); /*lint !e866*/
910 for( i = 0; i < nsubscipconss[b]; ++i )
911 {
913 }
914 }
915 }
916
917 if( !valid )
918 return SCIP_INVALIDDATA;
919
920 return SCIP_OKAY;
921}
922
923/** returns the subscipconss array of the given decomposition */
925 GCG_DECOMP* decomp /**< decomposition data structure */
926 )
927{
928 assert(decomp != NULL);
929 return decomp->subscipconss;
930}
931
932/** returns the nsubscipconss array of the given decomposition */
934 GCG_DECOMP* decomp /**< decomposition data structure */
935 )
936{
937 assert(decomp != NULL);
938 return decomp->nsubscipconss;
939}
940
941/** copies the input linkingconss array to the given decomposition */
943 GCG* gcg, /**< GCG data structure */
944 GCG_DECOMP* decomp, /**< decomposition data structure */
945 SCIP_CONS** linkingconss, /**< linkingconss array */
946 int nlinkingconss /**< number of linkingconss per block */
947 )
948{
949 SCIP* scip;
950 assert(gcg != NULL);
951 assert(decomp != NULL);
952 assert(linkingconss != NULL);
953 assert(nlinkingconss >= 0);
954
955 assert(decomp->linkingconss == NULL);
956 assert(decomp->nlinkingconss == 0);
957
959 decomp->nlinkingconss = nlinkingconss;
960
961 if( nlinkingconss > 0 )
962 {
963 int i;
964 int size;
965 assert(linkingconss != NULL);
966 size = SCIPcalcMemGrowSize(scip, nlinkingconss);
968 BMScopyMemoryArray(decomp->linkingconss, linkingconss, nlinkingconss);
969
970 for( i = 0; i < nlinkingconss; ++i )
971 {
973 }
974 }
975
976 if( (linkingconss == NULL) != (nlinkingconss == 0) )
977 {
978 SCIPerrorMessage("Number of linking constraints and linking constraint array are inconsistent.\n");
979 return SCIP_INVALIDDATA;
980 }
981 return SCIP_OKAY;
982}
983
984/** returns the linkingconss array of the given decomposition */
986 GCG_DECOMP* decomp /**< decomposition data structure */
987 )
988{
989 assert(decomp != NULL);
990
991 return decomp->linkingconss;
992}
993
994/** returns the nlinkingconss array of the given decomposition */
996 GCG_DECOMP* decomp /**< decomposition data structure */
997 )
998{
999 assert(decomp != NULL);
1000 assert(decomp->nlinkingconss >= 0);
1001
1002 return decomp->nlinkingconss;
1003}
1004
1005
1006/** copies the input linkingvars array to the given decdecomp structure */
1008 GCG* gcg, /**< GCG data structure */
1009 GCG_DECOMP* decomp, /**< decomposition data structure */
1010 SCIP_VAR** linkingvars, /**< linkingvars array */
1011 int nlinkingvars, /**< number of total linkingvars (including fixed linking vars, ) */
1012 int nfixedlinkingvars, /**< number of fixed linking variables */
1013 int nmastervars /**< number of linking variables that are purely master variables */
1014
1015 )
1016{
1017 SCIP* scip;
1018 assert(gcg != NULL);
1019 assert(decomp != NULL);
1020 assert(linkingvars != NULL || nlinkingvars == 0);
1021
1022 assert(decomp->linkingvars == NULL);
1023 assert(decomp->nlinkingvars == 0);
1024
1026 decomp->nlinkingvars = nlinkingvars;
1027 decomp->nmastervars = nmastervars;
1028 decomp->nfixedlinkingvars = nfixedlinkingvars;
1029
1030 if( nlinkingvars > 0 )
1031 {
1032 int i;
1033 int size;
1034 assert(linkingvars != NULL);
1035 size = SCIPcalcMemGrowSize(scip, nlinkingvars);
1037 BMScopyMemoryArray(decomp->linkingvars, linkingvars, nlinkingvars);
1038
1039 for( i = 0; i < nlinkingvars; ++i )
1040 {
1041 SCIP_CALL( SCIPcaptureVar(scip, decomp->linkingvars[i]) );
1042 }
1043 }
1044
1045 if( (linkingvars == NULL) != (nlinkingvars == 0) )
1046 {
1047 SCIPerrorMessage("Number of linking variables and linking variable array are inconsistent.\n");
1048 return SCIP_INVALIDDATA;
1049 }
1050
1051 return SCIP_OKAY;
1052}
1053
1054
1055/** returns the linkingvars array of the given decomposition */
1057 GCG_DECOMP* decomp /**< decomposition data structure */
1058 )
1059{
1060 assert(decomp != NULL);
1061
1062 return decomp->linkingvars;
1063}
1064
1065/** returns the nlinkingvars array of the given decomposition */
1067 GCG_DECOMP* decomp /**< decomposition data structure */
1068 )
1069{
1070 assert(decomp != NULL);
1071 assert(decomp->nlinkingvars >= 0);
1072
1073 return decomp->nlinkingvars;
1074}
1075
1076/** returns the nlinkingvars array of the given decomposition */
1078 GCG_DECOMP* decomp /**< decomposition data structure */
1079 )
1080{
1081 assert(decomp != NULL);
1082 assert(decomp->nfixedlinkingvars >= 0);
1083
1084 return decomp->nfixedlinkingvars;
1085}
1086
1087
1088/** returns the number of linking variables that are purely master ("static") variables of the given decomposition */
1090 GCG_DECOMP* decomp /**< decomposition data structure */
1091 )
1092{
1093 assert(decomp != NULL);
1094 assert(decomp->nmastervars >= 0);
1095
1096 return decomp->nmastervars;
1097}
1098
1099
1100/** copies the input stairlinkingvars array to the given decomposition */
1102 GCG* gcg, /**< GCG data structure */
1103 GCG_DECOMP* decomp, /**< decomposition data structure */
1104 SCIP_VAR*** stairlinkingvars, /**< stairlinkingvars array */
1105 int* nstairlinkingvars /**< number of linkingvars per block */
1106 )
1107{
1108 SCIP* scip;
1109 SCIP_Bool valid;
1110 int b;
1111 int i;
1112 assert(gcg != NULL);
1113 assert(decomp != NULL);
1114 assert(stairlinkingvars != NULL);
1115 assert(nstairlinkingvars != NULL);
1116
1117 assert(decomp->nblocks >= 0);
1118
1119 assert(decomp->stairlinkingvars == NULL);
1120 assert(decomp->nstairlinkingvars == NULL);
1121
1123 valid = TRUE; /**@todo A valid check needs to be implemented */
1124
1125 if( decomp->nblocks == 0 )
1126 return SCIP_OKAY;
1127
1128 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &decomp->stairlinkingvars, decomp->nblocks) ); /* this is more efficient */
1129 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &decomp->nstairlinkingvars, decomp->nblocks) ); /* this is more efficient */
1130
1131 assert(decomp->stairlinkingvars != NULL);
1132 assert(decomp->nstairlinkingvars != NULL);
1133
1136
1137 for( b = 0; b < decomp->nblocks-1; ++b )
1138 {
1139 assert(nstairlinkingvars[b] > 0 || stairlinkingvars[b] == NULL);
1140 decomp->nstairlinkingvars[b] = nstairlinkingvars[b];
1141 if( stairlinkingvars[b] != NULL )
1142 {
1143 int size = SCIPcalcMemGrowSize(scip, nstairlinkingvars[b]);
1144 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(decomp->stairlinkingvars[b]), size) ); /*lint !e866 */
1145 BMScopyMemoryArray(decomp->stairlinkingvars[b], stairlinkingvars[b], nstairlinkingvars[b]); /*lint !e866 */
1146 }
1147 else
1148 {
1149 decomp->stairlinkingvars[b] = NULL;
1150 }
1151 }
1152
1153 decomp->nstairlinkingvars[decomp->nblocks - 1] = 0;
1154 decomp->stairlinkingvars[decomp->nblocks -1] = NULL;
1155
1156 for( b = 0; b < decomp->nblocks-1; ++b )
1157 {
1158 for( i = 0; i < nstairlinkingvars[b]; ++i )
1159 {
1160 assert(stairlinkingvars[b] != NULL);
1162 }
1163 }
1164 if( !valid ) /*lint !e774 it is always true, see above */
1165 {
1166 SCIPerrorMessage("The staircase linking variables are inconsistent.\n");
1167 return SCIP_INVALIDDATA;
1168 }
1169 return SCIP_OKAY;
1170}
1171
1172/** returns the stairlinkingvars array of the given decomposition */
1174 GCG_DECOMP* decomp /**< decomposition data structure */
1175 )
1176{
1177 assert(decomp != NULL);
1178 return decomp->stairlinkingvars;
1179}
1180
1181/** returns the nstairlinkingvars array of the given decomposition */
1183 GCG_DECOMP* decomp /**< decomposition data structure */
1184 )
1185{
1186 assert(decomp != NULL);
1187 assert(decomp->nstairlinkingvars != NULL );
1188 return decomp->nstairlinkingvars;
1189}
1190
1191/** returns the total number of stairlinkingvars array of the given decomposition */
1193 GCG_DECOMP* decomp /**< decomposition data structure */
1194 )
1195{
1196 int sum;
1197 int b;
1198
1199 sum = 0;
1200
1201 for ( b = 0; b < GCGdecompGetNBlocks(decomp); ++b)
1202 sum += GCGdecompGetNStairlinkingvars(decomp)[b];
1203
1204 return sum;
1205}
1206
1207
1208/** sets the vartoblock hashmap of the given decomposition */
1210 GCG_DECOMP* decomp, /**< decomposition data structure */
1211 SCIP_HASHMAP* vartoblock /**< Vartoblock hashmap */
1212 )
1213{
1214 assert(decomp != NULL);
1215 assert(vartoblock != NULL);
1216
1217 decomp->vartoblock = vartoblock;
1218}
1219
1220/** returns the vartoblock hashmap of the given decomposition */
1222 GCG_DECOMP* decomp /**< decomposition data structure */
1223 )
1224{
1225 assert(decomp != NULL);
1226
1227 return decomp->vartoblock;
1228}
1229
1230/** sets the constoblock hashmap of the given decomposition */
1232 GCG_DECOMP* decomp, /**< decomposition data structure */
1233 SCIP_HASHMAP* constoblock /**< Constoblock hashmap */
1234 )
1235{
1236 assert(decomp != NULL);
1237 assert(constoblock != NULL);
1238
1239 decomp->constoblock = constoblock;
1240}
1241
1242/** returns the constoblock hashmap of the given decomposition */
1244 GCG_DECOMP* decomp /**< decomposition data structure */
1245 )
1246{
1247 assert(decomp != NULL);
1248
1249 return decomp->constoblock;
1250}
1251
1252/** sets the varindex hashmap of the given decomposition */
1254 GCG_DECOMP* decomp, /**< decomposition data structure */
1255 SCIP_HASHMAP* varindex /**< Varindex hashmap */
1256 )
1257{
1258 assert(decomp != NULL);
1259 assert(varindex != NULL);
1260 decomp->varindex = varindex;
1261}
1262
1263/** returns the varindex hashmap of the given decomposition */
1265 GCG_DECOMP* decomp /**< decomposition data structure */
1266 )
1267{
1268 assert(decomp != NULL);
1269 return decomp->varindex;
1270}
1271
1272/** sets the consindex hashmap of the given decomposition */
1274 GCG_DECOMP* decomp, /**< decomposition data structure */
1275 SCIP_HASHMAP* consindex /**< Consindex hashmap */
1276 )
1277{
1278 assert(decomp != NULL);
1279 assert(consindex != NULL);
1280 decomp->consindex = consindex;
1281}
1282
1283/** returns the consindex hashmap of the given decomposition */
1285 GCG_DECOMP* decomp /**< decomposition data structure */
1286 )
1287{
1288 assert(decomp != NULL);
1289 return decomp->consindex;
1290}
1291
1292/** completely initializes decomposition structure from the values of the hashmaps */
1294 GCG* gcg, /**< GCG data structure */
1295 GCG_DECOMP* decomp, /**< decomposition data structure */
1296 SCIP_HASHMAP* vartoblock, /**< variable to block hashmap */
1297 SCIP_HASHMAP* constoblock, /**< constraint to block hashmap */
1298 int nblocks, /**< number of blocks */
1299 SCIP_Bool staircase /**< should the decomposition be a staircase structure */
1300 )
1301{
1302 SCIP* scip;
1303 SCIP_HASHMAP* varindex;
1304 SCIP_HASHMAP* consindex;
1305 int* nsubscipconss;
1306 int* nsubscipvars;
1307 int* nstairlinkingvars;
1308 SCIP_VAR*** stairlinkingvars;
1309 SCIP_CONS*** subscipconss;
1310 SCIP_Bool success;
1311 int cindex;
1312 int cumindex;
1313 SCIP_Bool haslinking;
1314 int i;
1315 int b;
1316 SCIP_VAR** curvars;
1317 int ncurvars;
1318 int j;
1319
1320 SCIP_VAR** vars;
1321 int nvars;
1322 SCIP_CONS** conss;
1323 int nconss;
1324
1325 assert(gcg != NULL);
1326 assert(decomp != NULL);
1327 assert(vartoblock != NULL);
1328 assert(constoblock != NULL);
1329 assert(nblocks >= 0);
1330
1332 conss = SCIPgetConss(scip);
1333 nconss = SCIPgetNConss(scip);
1334 vars = SCIPgetVars(scip);
1335 nvars = SCIPgetNVars(scip);
1336
1337 assert(vars != NULL);
1338 assert(conss != NULL);
1339
1340 GCGdecompSetNBlocks(decomp, nblocks);
1341
1343 SCIP_CALL_QUIET( fillOutConsFromConstoblock(gcg, decomp, constoblock, nblocks, conss, nconss, &haslinking) );
1344
1345 if( haslinking )
1346 {
1347 SCIPdebugMessage("Decomposition has linking constraints and is bordered.\n");
1349 }
1350
1351 SCIP_CALL( fillOutVarsFromVartoblock(gcg, decomp, vartoblock, nblocks, vars, nvars, &haslinking) );
1352
1353 if( haslinking )
1354 {
1355 SCIPdebugMessage("Decomposition has linking variables and is arrowhead.\n");
1357 }
1358
1359 if( !staircase )
1360 {
1362 return SCIP_OKAY;
1363 }
1364
1365 SCIP_CALL( SCIPhashmapCreate(&varindex, SCIPblkmem(scip), nvars) );
1366 SCIP_CALL( SCIPhashmapCreate(&consindex, SCIPblkmem(scip), nconss) );
1367 SCIP_CALL( SCIPallocBufferArray(scip, &stairlinkingvars, nblocks) );
1368 SCIP_CALL( SCIPallocBufferArray(scip, &nstairlinkingvars, nblocks) );
1369
1370 for( i = 0; i < nblocks; ++i )
1371 {
1372 SCIP_CALL( SCIPallocBufferArray(scip, &(stairlinkingvars[i]), nvars) ); /*lint !e866*/
1373 nstairlinkingvars[i] = 0;
1374 }
1375
1376 nsubscipconss = GCGdecompGetNSubscipconss(decomp);
1377 subscipconss = GCGdecompGetSubscipconss(decomp);
1378 nsubscipvars = GCGdecompGetNSubscipvars(decomp);
1379
1380 cindex = 0;
1381 cumindex = 0;
1382
1383 /* try to deduce staircase map */
1384 for( b = 0; b < nblocks; ++b )
1385 {
1386 int idx = 0;
1387 SCIPdebugMessage("block %d (%d vars):\n", b, nsubscipvars[b]);
1388
1389 for( i = 0; i < nsubscipconss[b]; ++i )
1390 {
1391
1392 int linkindex = 0;
1393 SCIP_CONS* cons = subscipconss[b][i];
1394
1395 SCIP_CALL( SCIPhashmapInsert(consindex, cons, (void*)(size_t) (cindex+1)) );
1396 ++cindex;
1397 SCIP_CALL( SCIPgetConsNVars(scip, cons, &ncurvars, &success) );
1398 assert(success);
1399
1400 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
1401
1402 SCIP_CALL( SCIPgetConsVars(scip, cons, curvars, ncurvars, &success) );
1403 assert(success);
1404
1405 for( j = 0; j < ncurvars; ++j )
1406 {
1407 SCIP_VAR* probvar = SCIPvarGetProbvar(curvars[j]);
1408
1409 if( SCIPvarGetStatus(probvar) == SCIP_VARSTATUS_FIXED )
1410 continue;
1411
1412 /* if the variable is linking */
1413 if( (int)(size_t)SCIPhashmapGetImage(vartoblock, probvar) >= nblocks+1 ) /*lint !e507*/
1414 {
1415 /* if it has not been already assigned, it links to the next block */
1416 if( !SCIPhashmapExists(varindex, probvar) )
1417 {
1418 int vindex = cumindex+nsubscipvars[b]+linkindex+1;
1419 SCIPdebugMessage("assigning link var <%s> to index <%d>\n", SCIPvarGetName(probvar), vindex);
1420 SCIP_CALL( SCIPhashmapInsert(varindex, probvar, (void*)(size_t)(vindex)) );
1421 stairlinkingvars[b][nstairlinkingvars[b]] = probvar;
1422 ++(nstairlinkingvars[b]);
1423 linkindex++;
1424 }
1425 }
1426 else
1427 {
1428 if( !SCIPhashmapExists(varindex, probvar) )
1429 {
1430 int vindex = cumindex+idx+1;
1431 assert(((int) (size_t) SCIPhashmapGetImage(vartoblock, probvar)) -1 == b); /*lint !e507*/
1432 SCIPdebugMessage("assigning block var <%s> to index <%d>\n", SCIPvarGetName(probvar), vindex);
1433 SCIP_CALL( SCIPhashmapInsert(varindex, probvar, (void*)(size_t)(vindex)) );
1434 ++idx;
1435 }
1436 }
1437 }
1438 SCIPfreeBufferArray(scip, &curvars);
1439 }
1440 if( b < nblocks-1 )
1441 {
1442 cumindex += nsubscipvars[b] + nstairlinkingvars[b];
1443 }
1444 }
1445
1446 GCGdecompSetVarindex(decomp, varindex);
1447 GCGdecompSetConsindex(decomp, consindex);
1449
1450 for( b = nblocks-1; b >= 0; --b )
1451 {
1452 if( nstairlinkingvars[b] == 0 )
1453 {
1454 SCIPfreeBufferArrayNull(scip, &(stairlinkingvars[b]));
1455 }
1456 }
1457
1458 SCIP_CALL( GCGdecompSetStairlinkingvars(gcg, decomp, stairlinkingvars, nstairlinkingvars) );
1459
1460 for( b = nblocks-1; b >= 0; --b )
1461 {
1462 SCIPfreeBufferArrayNull(scip, &stairlinkingvars[b]);
1463 }
1464 SCIPfreeBufferArray(scip, &nstairlinkingvars);
1465 SCIPfreeBufferArray(scip, &stairlinkingvars);
1466
1468
1469 return SCIP_OKAY;
1470}
1471
1472/** completely fills out decomposition structure from only the constraint partition in the following manner:
1473 * given constraint block/border assignment (by constoblock), one gets the following assignment of probvars:
1474 * let C(j) be the set of constraints containing variable j, set block of j to
1475 * (i) constoblock(i) iff constoblock(i1) == constoblock(i2) for all i1,i2 in C(j) with constoblock(i1) != nblocks+1 && constoblock(i2) != nblocks+1
1476 * (ii) nblocks+2 ["linking var"] iff exists i1,i2 with constoblock(i1) != constoblock(i2) && constoblock(i1) != nblocks+1 && constoblock(i2) != nblocks+1
1477 * (iii) nblocks+1 ["master var"] iff constoblock(i) == nblocks+1 for all i in C(j)
1478 */
1480 GCG* gcg, /**< GCG data structure */
1481 GCG_DECOMP* decomp, /**< decomposition data structure */
1482 SCIP_HASHMAP* constoblock, /**< constraint to block hashmap, start with 1 for first block and nblocks+1 for linking constraints */
1483 int nblocks, /**< number of blocks */
1484 SCIP_Bool staircase /**< should the decomposition be a staircase structure */
1485 )
1486{
1487 SCIP* scip;
1488 SCIP_HASHMAP* vartoblock;
1489 int i;
1490 int j;
1491 SCIP_VAR** vars;
1492 int nvars;
1493 SCIP_CONS** conss;
1494 int nconss;
1495 SCIP_VAR** curvars;
1496 int ncurvars;
1497 SCIP_Bool haslinking;
1498 SCIP_Bool success;
1499 SCIP_RETCODE retcode;
1500
1501 assert(gcg != NULL);
1502 assert(decomp != NULL);
1503 assert(constoblock != NULL);
1504 assert(nblocks >= 0);
1505
1507 conss = SCIPgetConss(scip);
1508 nconss = SCIPgetNConss(scip);
1509 vars = SCIPgetVars(scip);
1510 nvars = SCIPgetNVars(scip);
1511
1512 assert(vars != NULL);
1513 assert(nvars > 0);
1514 assert(conss != NULL);
1515 assert(nconss > 0);
1516
1517 SCIP_CALL( SCIPhashmapCreate(&vartoblock, SCIPblkmem(scip), nvars) );
1518 haslinking = FALSE;
1519 for( i = 0; i < nconss; ++i )
1520 {
1521 int consblock;
1522
1523 SCIP_CALL( SCIPgetConsNVars(scip, conss[i], &ncurvars, &success) );
1524 assert(success);
1525
1526 if( ncurvars == 0 )
1527 continue;
1528
1529 consblock = (int)(size_t)SCIPhashmapGetImage(constoblock, conss[i]); /*lint !e507*/
1530
1531 assert(consblock > 0 && consblock <= nblocks+1);
1532 if( consblock == nblocks+1 )
1533 {
1534 SCIPdebugMessage("cons <%s> is linking and need not be handled\n", SCIPconsGetName(conss[i]));
1535 continue;
1536 }
1537
1538 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
1539
1540 SCIP_CALL( SCIPgetConsVars(scip, conss[i], curvars, ncurvars, &success) );
1541 assert(success);
1542 SCIPdebugMessage("cons <%s> (%d vars) is in block %d.\n", SCIPconsGetName(conss[i]), ncurvars, consblock);
1543 assert(consblock <= nblocks);
1544
1545 for( j = 0; j < ncurvars; ++j )
1546 {
1547 int varblock;
1548 SCIP_VAR* probvar = SCIPvarGetProbvar(curvars[j]);
1549
1550 if( SCIPvarGetStatus(probvar) == SCIP_VARSTATUS_FIXED )
1551 continue;
1552
1553 assert(SCIPvarIsActive(probvar));
1554
1555 if( SCIPhashmapExists(vartoblock, probvar) )
1556 varblock = (int) (size_t) SCIPhashmapGetImage(vartoblock, probvar); /*lint !e507*/
1557 else
1558 varblock = nblocks+1;
1559
1560 /* The variable is currently in no block */
1561 if( varblock == nblocks+1 )
1562 {
1563 SCIPdebugMessage(" var <%s> not been handled before, adding to block %d\n", SCIPvarGetName(probvar), consblock);
1564 SCIP_CALL( SCIPhashmapSetImage(vartoblock, probvar, (void*) (size_t) consblock) );
1565 }
1566 /* The variable is already in a different block */
1567 else if( varblock != consblock )
1568 {
1569 assert(varblock <= nblocks || varblock == nblocks+2);
1570 SCIPdebugMessage(" var <%s> has been handled before, adding to linking (%d != %d)\n", SCIPvarGetName(probvar), consblock, varblock);
1571 SCIP_CALL( SCIPhashmapSetImage(vartoblock, probvar, (void*) (size_t) (nblocks+2)) );
1572 haslinking = TRUE;
1573 }
1574 else
1575 {
1576 assert(consblock == varblock);
1577 SCIPdebugMessage(" var <%s> is handled and in same block as cons (%d == %d).\n", SCIPvarGetName(probvar), consblock, varblock);
1578 }
1579 }
1580
1581 SCIPfreeBufferArray(scip, &curvars);
1582 }
1583
1584 /* Handle variables that do not appear in any pricing problem, those will be copied directly to the master */
1585 for( i = 0; i < nvars; ++i )
1586 {
1587 if( !SCIPhashmapExists(vartoblock, vars[i]) )
1588 {
1589 SCIPdebugMessage(" var <%s> not handled at all and now in master\n", SCIPvarGetName(vars[i]));
1590 SCIP_CALL( SCIPhashmapSetImage(vartoblock, vars[i], (void*) (size_t) (nblocks+1)) );
1591 }
1592 }
1593
1594 retcode = GCGfilloutDecompFromHashmaps(gcg, decomp, vartoblock, constoblock, nblocks, staircase && haslinking);
1595 if( retcode != SCIP_OKAY )
1596 {
1597 SCIPhashmapFree(&vartoblock);
1598 return retcode;
1599 }
1600
1601 return SCIP_OKAY;
1602}
1603
1604/** sets the detector for the given decomposition */
1606 GCG_DECOMP* decomp, /**< decomposition data structure */
1607 GCG_DETECTOR* detector /**< detector data structure */
1608 )
1609{
1610 assert(decomp != NULL);
1611
1612 decomp->detector = detector;
1613}
1614
1615/** gets the detector for the given decomposition */
1617 GCG_DECOMP* decomp /**< decomposition data structure */
1618 )
1619{
1620 assert(decomp != NULL);
1621
1622 return decomp->detector;
1623}
1624
1625/** gets the detectors for the given decomposition */
1627 GCG_DECOMP* decomp /**< decomposition data structure */
1628 )
1629{
1630 assert(decomp != NULL);
1631
1632 return decomp->detectorchain;
1633}
1634
1636 GCG* gcg,
1637 GCG_DECOMP* decomp,
1638 GCG_DETECTOR** detectors,
1639 int ndetectors
1640 )
1641{
1642 SCIP* scip;
1643 int d;
1644
1646 /* resize detectorchain */
1647 int size = SCIPcalcMemGrowSize( scip, ndetectors);
1649
1650 /* clear former */
1651 BMSclearMemoryArray(decomp->detectorchain, size);
1652
1653 for( d = 0; d < ndetectors; ++d )
1654 {
1655 decomp->detectorchain[d] = detectors[d];
1656 }
1657
1658 decomp->sizedetectorchain = ndetectors;
1659 return SCIP_OKAY;
1660}
1661
1662/** gets the number of detectors for the given decomposition */
1664 GCG_DECOMP* decomp /**< decomposition data structure */
1665 )
1666{
1667 assert(decomp != NULL);
1668
1669 return decomp->sizedetectorchain;
1670}
1671
1672/** sets the id of the original partialdec */
1674 GCG_DECOMP* decomp, /**< decomposition data structure */
1675 int id /**< ID of partialdec */
1676 )
1677{
1678 assert(decomp != NULL);
1679 assert(id >= 0);
1680
1681 decomp->partialdecid = id;
1682}
1683
1684/** gets the id of the original partialdec */
1686 GCG_DECOMP* decomp /**< decomposition data structure */
1687 )
1688{
1689 assert(decomp != NULL);
1690 return decomp->partialdecid;
1691}
1692
1693/** sets the detector clock times of the detectors of the detector chain */
1695 GCG* gcg, /**< GCG data structure */
1696 GCG_DECOMP* decomp, /**< decomposition data structure */
1697 SCIP_Real* detectorClockTimes /**< time used by the detectors */
1698 )
1699{
1700 SCIP* scip;
1701 int d;
1702
1703 int size;
1706
1707 assert(decomp->sizedetectorchain > 0);
1709
1711
1712 for ( d = 0; d < decomp->sizedetectorchain; ++d )
1713 {
1714 decomp->detectorclocktimes[d] = detectorClockTimes[d];
1715 }
1716
1717 return;
1718}
1719
1720/** gets the detector clock times of the detectors of the detector chain */
1722 GCG_DECOMP* decomp /**< decomposition data structure */
1723 )
1724{
1725 return decomp->detectorclocktimes;
1726}
1727
1728/** sets the detector clock times of the detectors of the detector chain */
1731 GCG* gcg, /**< GCG data structure */
1732 GCG_DECOMP* decomp, /**< decomposition data structure */
1733 const char* detectorchainstring /**< string for the detector information working on that decomposition */
1734 )
1735{
1736 SCIP* scip;
1738 SCIP_CALL (SCIPduplicateBlockMemoryArray(scip, &(decomp->detectorchainstring), detectorchainstring, SCIP_MAXSTRLEN ) );
1739 return SCIP_OKAY;
1740
1741}
1742
1743/** sets the detector clock times of the detectors of the detector chain */
1746 GCG* gcg, /**< GCG data structure */
1747 GCG_DECOMP* decomp /**< decomposition data structure */
1748 )
1749{
1750 return decomp->detectorchainstring;
1751}
1752
1753/** sets the percentages of variables assigned to the border of the corresponding detectors (of the detector chain) on this decomposition */
1755 GCG* gcg, /**< GCG data structure */
1756 GCG_DECOMP* decomp, /**< decomposition data structure */
1757 SCIP_Real* pctVarsToBorder /**< percentage of variables assigned to border */
1758 )
1759{
1760 SCIP* scip;
1761 int d;
1762 int size;
1765
1766 assert(decomp->sizedetectorchain > 0);
1767
1769
1770 BMSclearMemoryArray(decomp->pctvarstoborder, size);
1771
1772 for ( d = 0; d < decomp->sizedetectorchain; ++d )
1773 {
1774 decomp->pctvarstoborder[d] = pctVarsToBorder[d];
1775 }
1776}
1777
1778/** gets the percentages of variables assigned to the border of the corresponding detectors (of the detector chain) on this decomposition */
1781 GCG_DECOMP* decomp /**< decomposition data structure */
1782 )
1783{
1784 return decomp->pctvarstoborder;
1785}
1786
1787/** sets the percentages of constraints assigned to the border of the corresponding detectors (of the detector chain) on this decomposition */
1789 GCG* gcg, /**< GCG data structure */
1790 GCG_DECOMP* decomp, /**< decomposition data structure */
1791 SCIP_Real* pctConssToBorder /**< percentage of constraints assigned to border */
1792 )
1793{
1794 SCIP* scip;
1795 int d;
1796 int size;
1799
1800
1801 assert(decomp->sizedetectorchain > 0);
1802
1804
1806
1807 for ( d = 0; d < decomp->sizedetectorchain; ++d )
1808 {
1809 decomp->pctconsstoborder[d] = pctConssToBorder[d];
1810 }
1811
1812 return;
1813}
1814
1815/** gets the percentages of constraints assigned to the border of the corresponding detectors (of the detector chain) on this decomposition */
1817 GCG_DECOMP* decomp /**< decomposition data structure */
1818 )
1819{
1820 return decomp->pctconsstoborder;
1821}
1822
1823/** sets the percentages of variables assigned to some block of the corresponding detectors (of the detector chain) on this decomposition */
1825 GCG* gcg, /**< GCG data structure */
1826 GCG_DECOMP* decomp, /**< decomposition data structure */
1827 SCIP_Real* pctVarsToBlock /**< percentage of variables assigned to some block in the detector chain */
1828 )
1829{
1830 SCIP* scip;
1831 int d;
1832 int size;
1833
1834 assert(decomp->sizedetectorchain > 0);
1837
1838
1840
1841 BMSclearMemoryArray(decomp->pctvarstoblock, size);
1842
1843 for ( d = 0; d < decomp->sizedetectorchain; ++d )
1844 {
1845 decomp->pctvarstoblock[d] = pctVarsToBlock[d];
1846 }
1847 }
1848
1849/** gets the percentages of variables assigned to some block of the corresponding detectors (of the detector chain) on this decomposition */
1851 GCG_DECOMP* decomp /**< decomposition data structure */
1852 )
1853{
1854 return decomp->pctvarstoblock;
1855}
1856
1857/** sets the percentages of constraints assigned to some block of the corresponding detectors (of the detector chain) on this decomposition */
1859 GCG* gcg, /**< GCG data structure */
1860 GCG_DECOMP* decomp, /**< decomposition data structure */
1861 SCIP_Real* pctConssToBlock /**< percentage of constraints assigned to some block in the detector chain */
1862 )
1863{
1864 SCIP* scip;
1865 int d;
1866 int size;
1867
1868 assert(decomp->sizedetectorchain > 0);
1871
1873
1874 BMSclearMemoryArray(decomp->pctconsstoblock, size);
1875
1876 for ( d = 0; d < decomp->sizedetectorchain; ++d )
1877 {
1878 decomp->pctconsstoblock[d] = pctConssToBlock[d];
1879 }
1880
1881 return;
1882}
1883
1884/** gets the percentages of constraints assigned to some block of the corresponding detectors (of the detector chain) on this decomposition */
1887 GCG_DECOMP* decomp /**< decomposition data structure */
1888 )
1889{
1890 return decomp->pctconsstoblock;
1891}
1892
1893
1894/** sets the percentages of variables assigned to some block of the corresponding detectors (of the detector chain) on this decomposition */
1896 GCG* gcg, /**< GCG data structure */
1897 GCG_DECOMP* decomp, /**< decomposition data structure */
1898 SCIP_Real* pctVarsFromOpen /**< percentage of open variables assigned to some block in the detector chain */
1899 )
1900{
1901 int d;
1902 int size;
1904
1905 assert(decomp->sizedetectorchain > 0);
1906
1907
1909
1910
1912
1913 BMSclearMemoryArray(decomp->pctvarsfromopen, size);
1914
1915 for ( d = 0; d < decomp->sizedetectorchain; ++d )
1916 {
1917 decomp->pctvarsfromopen[d] = pctVarsFromOpen[d];
1918 }
1919
1920 return;
1921}
1922
1923/** gets the percentages of variables assigned to some block of the corresponding detectors (of the detector chain) on this decomposition */
1925 GCG_DECOMP* decomp /**< decomposition data structure */
1926 )
1927{
1928 return decomp->pctvarsfromopen;
1929}
1930
1931/** sets the percentages of constraints assigned to some block of the corresponding detectors (of the detector chain) on this decomposition */
1933 GCG* gcg, /**< GCG data structure */
1934 GCG_DECOMP* decomp, /**< decomposition data structure */
1935 SCIP_Real* pctConssFromOpen /**< percentage of open variables assigned to some block in the detector chain */
1936 )
1937{
1938 SCIP* scip;
1939 int d;
1940 int size;
1941
1942 assert(decomp->sizedetectorchain > 0);
1943
1946
1947
1949
1951
1952 for ( d = 0; d < decomp->sizedetectorchain; ++d )
1953 {
1954 decomp->pctconssfromopen[d] = pctConssFromOpen[d];
1955 }
1956
1957 return;
1958}
1959
1960/** gets the percentages of constraints assigned to some block of the corresponding detectors (of the detector chain)
1961 * on this decomposition */
1963 GCG_DECOMP* decomp /**< decomposition data structure */
1964 )
1965{
1966 return decomp->pctconssfromopen;
1967}
1968
1969/** sets the number of new blocks of the corresponding detectors (of the detector chain) on this decomposition */
1971 GCG* gcg, /**< GCG data structure */
1972 GCG_DECOMP* decomp, /**< decomposition data structure */
1973 int* nNewBlocks /**< number of newly found blocks in this decomposition */
1974 )
1975{
1976 SCIP* scip;
1977 int d;
1978 int size;
1979
1980 assert(decomp->sizedetectorchain > 0);
1983
1985
1986 BMSclearMemoryArray(decomp->nnewblocks, size);
1987
1988 for ( d = 0; d < decomp->sizedetectorchain; ++d )
1989 {
1990 decomp->nnewblocks[d] = nNewBlocks[d];
1991 }
1992
1993 return;
1994}
1995
1996/** gets the number of new blocks corresponding detectors (of the detector chain) on this decomposition */
1998 GCG_DECOMP* decomp /**< decomposition data structure */
1999 )
2000{
2001 return decomp->nnewblocks;
2002}
2003
2004/** transforms all constraints and variables, updating the arrays */
2006 GCG* gcg, /**< GCG data structure */
2007 GCG_DECOMP* decomp /**< decomposition data structure */
2008 )
2009{
2010 SCIP* scip;
2011 int b;
2012 int c;
2013 int v;
2014 SCIP_HASHMAP* newconstoblock;
2015 SCIP_HASHMAP* newvartoblock;
2016 SCIP_VAR* newvar;
2017
2020
2023
2024 /* transform all constraints and put them into constoblock */
2025 for( b = 0; b < decomp->nblocks; ++b )
2026 {
2027 for( c = 0; c < decomp->nsubscipconss[b]; ++c )
2028 {
2029 SCIP_CONS* newcons;
2030 SCIPdebugMessage("%d, %d: %s (%p, %s)\n", b, c, SCIPconsGetName(decomp->subscipconss[b][c]),
2031 (void*) decomp->subscipconss[b][c], SCIPconsIsTransformed(decomp->subscipconss[b][c])?"t":"o" );
2032 assert(decomp->subscipconss[b][c] != NULL);
2033 newcons = SCIPfindCons(scip, SCIPconsGetName(decomp->subscipconss[b][c]));
2034 if( newcons != decomp->subscipconss[b][c] )
2035 {
2036 SCIP_CALL( SCIPcaptureCons(scip, newcons) );
2037 SCIP_CALL( SCIPreleaseCons(scip, &(decomp->subscipconss[b][c])) );
2038 decomp->subscipconss[b][c] = newcons;
2039 }
2040 assert(decomp->subscipconss[b][c] != NULL);
2041 assert(!SCIPhashmapExists(newconstoblock, decomp->subscipconss[b][c]));
2042 SCIP_CALL( SCIPhashmapSetImage(newconstoblock, decomp->subscipconss[b][c], (void*) (size_t) (b+1)) );
2043 }
2044 }
2045 /* transform all variables and put them into vartoblock */
2046 for( b = 0; b < decomp->nblocks; ++b )
2047 {
2048 int idx;
2049 for( v = 0, idx = 0; v < decomp->nsubscipvars[b]; ++v )
2050 {
2051 assert(decomp->subscipvars[b][v] != NULL);
2052
2053 SCIPdebugMessage("%d, %d: %s (%p, %s)\n", b, v, SCIPvarGetName(decomp->subscipvars[b][v]),
2054 (void*)decomp->subscipvars[b][v], SCIPvarIsTransformed(decomp->subscipvars[b][v])?"t":"o" );
2055
2056 /* make sure that newvar is a transformed variable */
2057 SCIP_CALL( SCIPgetTransformedVar(scip, decomp->subscipvars[b][v], &newvar) );
2058 SCIP_CALL( SCIPreleaseVar(scip, &(decomp->subscipvars[b][v])) );
2059
2060 assert(newvar != NULL);
2061 assert(SCIPvarIsTransformed(newvar));
2062
2063 newvar = SCIPvarGetProbvar(newvar);
2064 assert(newvar != NULL);
2065
2066 /* the probvar can also be fixed, in which case we do not need it in the block; furthermore, multiple variables
2067 * can resolve to the same active problem variable, so we check whether we already handled the variable
2068 * @todo: why do we ignore fixed variables? They could still be present in constraints?
2069 */
2070 if( SCIPvarIsActive(newvar) && !SCIPhashmapExists(newvartoblock, newvar) )
2071 {
2072 decomp->subscipvars[b][idx] = newvar;
2073 SCIP_CALL( SCIPcaptureVar(scip, newvar) );
2074 SCIPdebugMessage("%d, %d: %s (%p, %s)\n", b, v, SCIPvarGetName(decomp->subscipvars[b][idx]),
2075 (void*)decomp->subscipvars[b][idx], SCIPvarIsTransformed(decomp->subscipvars[b][idx])?"t":"o" );
2076
2077 assert(decomp->subscipvars[b][idx] != NULL);
2078 assert(!SCIPhashmapExists(newvartoblock, decomp->subscipvars[b][idx]));
2079 SCIP_CALL( SCIPhashmapSetImage(newvartoblock, decomp->subscipvars[b][idx], (void*) (size_t) (b+1)) );
2080 ++idx;
2081 }
2082 }
2083 decomp->nsubscipvars[b] = idx;
2084 }
2085
2086 /* transform all linking constraints */
2087 for( c = 0; c < decomp->nlinkingconss; ++c )
2088 {
2089 SCIP_CONS* newcons;
2090
2091 SCIPdebugMessage("m, %d: %s (%s)\n", c, SCIPconsGetName(decomp->linkingconss[c]), SCIPconsIsTransformed(decomp->linkingconss[c])?"t":"o" );
2092 assert(decomp->linkingconss[c] != NULL);
2093 newcons = SCIPfindCons(scip, SCIPconsGetName(decomp->linkingconss[c]));
2094 if( newcons != decomp->linkingconss[c] )
2095 {
2096 SCIP_CALL( SCIPcaptureCons(scip, newcons) );
2097 SCIP_CALL( SCIPreleaseCons(scip, &(decomp->linkingconss[c])) );
2098 decomp->linkingconss[c] = newcons;
2099 }
2100 SCIP_CALL( SCIPhashmapSetImage(newconstoblock, decomp->linkingconss[c],(void*) (size_t) (decomp->nblocks+1) ) );
2101
2102 assert(decomp->linkingconss[c] != NULL);
2103 }
2104
2105 /* transform all linking variables */
2106 for( v = 0; v < decomp->nlinkingvars; ++v )
2107 {
2108 int block;
2109 SCIPdebugMessage("m, %d: %s (%p, %s)\n", v, SCIPvarGetName(decomp->linkingvars[v]),
2110 (void*)decomp->linkingvars[v], SCIPvarIsTransformed(decomp->linkingvars[v])?"t":"o");
2111 assert(decomp->linkingvars[v] != NULL);
2112
2113 if( !SCIPvarIsTransformed(decomp->linkingvars[v]) )
2114 {
2115 SCIP_CALL( SCIPgetTransformedVar(scip, decomp->linkingvars[v], &newvar) );
2116 newvar = SCIPvarGetProbvar(newvar);
2117 }
2118 else
2119 newvar = decomp->linkingvars[v];
2120
2121 block = (int) (size_t) SCIPhashmapGetImage(decomp->vartoblock, decomp->linkingvars[v]); /*lint !e507*/
2122 assert(block == decomp->nblocks +1 || block == decomp->nblocks +2);
2123 assert(newvar != NULL);
2124 assert(SCIPvarIsTransformed(newvar));
2125 SCIP_CALL( SCIPreleaseVar(scip, &(decomp->linkingvars[v])) );
2126
2127 decomp->linkingvars[v] = newvar;
2128 SCIP_CALL( SCIPcaptureVar(scip, decomp->linkingvars[v]) );
2129 SCIP_CALL( SCIPhashmapSetImage(newvartoblock, decomp->linkingvars[v], (void*) (size_t) (block) ) );
2130 SCIPdebugMessage("m, %d: %s (%p, %s)\n", v, SCIPvarGetName(decomp->linkingvars[v]),
2131 (void*)decomp->linkingvars[v], SCIPvarIsTransformed(decomp->linkingvars[v])?"t":"o");
2132 assert(decomp->linkingvars[v] != NULL);
2133 }
2134
2135 SCIPhashmapFree(&decomp->constoblock);
2136 decomp->constoblock = newconstoblock;
2137 SCIPhashmapFree(&decomp->vartoblock);
2138 decomp->vartoblock = newvartoblock;
2139
2141
2142 return SCIP_OKAY;
2143}
2144
2145/**
2146 * Remove all those constraints that were removed from the problem after the decomposition had been created
2147 */
2149 GCG* gcg, /**< GCG data structure */
2150 GCG_DECOMP* decdecomp /**< decomposition data structure */
2151 )
2152{
2153 SCIP* scip;
2154 int block;
2155 int c;
2156 int pos;
2157
2158 assert(gcg != NULL);
2159 assert(decdecomp != NULL);
2160
2162
2163 for( block = 0; block < decdecomp->nblocks; ++block )
2164 {
2165 for( c = 0, pos = 0; c < decdecomp->nsubscipconss[block]; ++c )
2166 {
2167 if( !SCIPconsIsDeleted(decdecomp->subscipconss[block][c]) )
2168 {
2169 decdecomp->subscipconss[block][pos] = decdecomp->subscipconss[block][c];
2170 ++pos;
2171 }
2172 else
2173 {
2174 SCIP_CALL( SCIPreleaseCons(scip, &decdecomp->subscipconss[block][c]) );
2175 }
2176 }
2178 SCIPcalcMemGrowSize(scip, decdecomp->nsubscipconss[block]), SCIPcalcMemGrowSize(scip, pos)) );
2179 decdecomp->nsubscipconss[block] = pos;
2180 }
2181
2182 for( c = 0, pos = 0; c < decdecomp->nlinkingconss; ++c )
2183 {
2184 if( !SCIPconsIsDeleted(decdecomp->linkingconss[c]) )
2185 {
2186 decdecomp->linkingconss[pos] = decdecomp->linkingconss[c];
2187 ++pos;
2188 }
2189 else
2190 {
2191 SCIP_CALL( SCIPreleaseCons(scip, &decdecomp->linkingconss[c]) );
2192 }
2193 }
2194
2195 if( pos != decdecomp->nlinkingconss && decdecomp->linkingconss != NULL )
2198 decdecomp->nlinkingconss = pos;
2199
2200 return SCIP_OKAY;
2201}
2202
2203/**
2204 * Adds all those constraints that were added to the problem after the decomposition had been created
2205 */
2207 GCG* gcg, /**< GCG data structure */
2208 GCG_DECOMP* decdecomp /**< decomposition data structure */
2209 )
2210{
2211 SCIP* scip;
2212 int c;
2213
2214 assert(gcg != NULL);
2215 assert(decdecomp != NULL);
2216
2218
2219 for( c = 0; c < SCIPgetNConss(scip); ++c )
2220 {
2221 SCIP_CONS* cons;
2222 cons = SCIPgetConss(scip)[c];
2223
2224
2225 if( !GCGisConsGCGCons(cons) && !SCIPhashmapExists(GCGdecompGetConstoblock(decdecomp), cons) )
2226 {
2227 int block;
2228 SCIP_CALL( GCGdetermineConsBlock(gcg, decdecomp, cons, &block) );
2229 SCIPdebugMessage("add remaining: cons <%s> in block %d/%d\n", SCIPconsGetName(cons), block, GCGdecompGetNBlocks(decdecomp) );
2230
2231 /* If the constraint has only variables appearing in the master only,
2232 * we assign it to the master rather than creating a new block
2233 */
2234 if( block == -1 || (block >= 0 && block == GCGdecompGetNBlocks(decdecomp) ) )
2235 {
2236 if( decdecomp->nlinkingconss == 0 )
2237 {
2238 int newsize;
2239 newsize = SCIPcalcMemGrowSize(scip, 1);
2240 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &decdecomp->linkingconss, newsize) );
2241
2242 switch( decdecomp->type )
2243 {
2245 decdecomp->type = GCG_DECTYPE_BORDERED;
2246 SCIPwarningMessage(scip, "Decomposition type changed to 'bordered' due to an added constraint.\n");
2247 break;
2249 decdecomp->type = GCG_DECTYPE_ARROWHEAD;
2250 SCIPwarningMessage(scip, "Decomposition type changed to 'arrowhead' due to an added constraint.\n");
2251 break;
2252 default:
2253 break;
2254 }
2255 }
2256 else
2257 {
2258 int oldsize;
2259 int newsize;
2260 oldsize = SCIPcalcMemGrowSize(scip, decdecomp->nlinkingconss);
2261 newsize = SCIPcalcMemGrowSize(scip, decdecomp->nlinkingconss+1);
2262 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &decdecomp->linkingconss, oldsize, newsize) );
2263 }
2264 decdecomp->linkingconss[decdecomp->nlinkingconss] = cons;
2265 decdecomp->nlinkingconss += 1;
2266 SCIP_CALL( SCIPhashmapInsert(decdecomp->constoblock, cons, (void*) (size_t) (GCGdecompGetNBlocks(decdecomp)+1)) );
2267 }
2268 else
2269 {
2270 int oldsize;
2271 int newsize;
2272 assert(block>=0);
2273
2274 oldsize = SCIPcalcMemGrowSize(scip, decdecomp->nsubscipconss[block]);
2275 newsize = SCIPcalcMemGrowSize(scip, decdecomp->nsubscipconss[block]+1);
2276
2277 assert(decdecomp->nsubscipconss[block] > 0);
2278 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &decdecomp->subscipconss[block], oldsize, newsize) ); /*lint !e866*/
2279 decdecomp->subscipconss[block][decdecomp->nsubscipconss[block]] = cons;
2280 decdecomp->nsubscipconss[block] += 1;
2281 SCIP_CALL( SCIPhashmapInsert(decdecomp->constoblock, cons, (void*) (size_t) (block+1)) );
2282 SCIP_CALL( assignConsvarsToBlock(gcg, decdecomp, cons, block) );
2283 }
2284 SCIP_CALL( SCIPcaptureCons(scip, cons) );
2285 }
2286 }
2287
2288
2289 return SCIP_OKAY;
2290}
2291
2292/** checks the consistency of the data structure
2293 *
2294 * In particular, it checks whether the redundant information in the structure agree and
2295 * whether the variables in the structure are both existant in the arrays and in the problem
2296 */
2298 GCG* gcg, /**< GCG data structure */
2299 GCG_DECOMP* decdecomp /**< decomposition data structure */
2300 )
2301{
2302#ifndef NDEBUG
2303 int c;
2304 int b;
2305 int v;
2307
2308 SCIPdebugMessage("Problem is %stransformed\n", SCIPgetStage(scip) >= SCIP_STAGE_TRANSFORMED ? "": "not ");
2309
2310 for( v = 0; v < SCIPgetNVars(scip); ++v )
2311 {
2313 continue;
2315 }
2316
2317 for( c = 0; c < SCIPgetNConss(scip); ++c )
2318 {
2320 {
2322 }
2323 }
2324
2325 /* Check whether subscipcons are correct */
2326 for( b = 0; b < GCGdecompGetNBlocks(decdecomp); ++b )
2327 {
2328 for( c = 0; c < GCGdecompGetNSubscipconss(decdecomp)[b]; ++c )
2329 {
2330 SCIP_VAR** curvars;
2331 int ncurvars;
2332 SCIP_CONS* cons = GCGdecompGetSubscipconss(decdecomp)[b][c];
2333
2334 SCIPdebugMessage("Cons <%s> in block %d = %d\n", SCIPconsGetName(cons), b, ((int) (size_t) SCIPhashmapGetImage(GCGdecompGetConstoblock(decdecomp), cons)) -1); /*lint !e507*/
2335 // @todo: remove if check when SCIPfindCons() can be called in stage SCIP_STAGE_INITSOLVE
2337 assert(SCIPfindCons(scip, SCIPconsGetName(cons)) != NULL);
2338 assert(((int) (size_t) SCIPhashmapGetImage(GCGdecompGetConstoblock(decdecomp), cons)) - 1 == b); /*lint !e507*/
2339 ncurvars = GCGconsGetNVars(scip, cons);
2340 if ( ncurvars == 0 )
2341 continue;
2342 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
2343 SCIP_CALL( GCGconsGetVars(scip, cons, curvars, ncurvars) );
2344
2345 for( v = 0; v < ncurvars; ++v )
2346 {
2347 int varblock;
2348 SCIP_VAR* var = SCIPvarGetProbvar(curvars[v]);
2349
2351 continue;
2352
2353 varblock = ((int) (size_t) SCIPhashmapGetImage(GCGdecompGetVartoblock(decdecomp), var)) - 1; /*lint !e507*/
2354 SCIPdebugMessage("\tVar <%s> in block %d = %d\n", SCIPvarGetName(var), b, varblock);
2355
2356 assert(SCIPfindVar(scip, SCIPvarGetName(var)) != NULL);
2357 assert(SCIPvarIsActive(var));
2358 assert(varblock == b || varblock == GCGdecompGetNBlocks(decdecomp)+1 );
2359
2360 }
2361 SCIPfreeBufferArray(scip, &curvars);
2362 }
2363
2364 assert((GCGdecompGetSubscipvars(decdecomp)[b] == NULL) == (GCGdecompGetNSubscipvars(decdecomp)[b] == 0));
2365
2366
2367 for( v = 0; v < GCGdecompGetNSubscipvars(decdecomp)[b]; ++v )
2368 {
2369 int varblock;
2370 SCIP_VAR* var = GCGdecompGetSubscipvars(decdecomp)[b][v];
2371 varblock = ((int) (size_t) SCIPhashmapGetImage(GCGdecompGetVartoblock(decdecomp), var)) - 1; /*lint !e507*/
2372 SCIPdebugMessage("Var <%s> in block %d = %d\n", SCIPvarGetName(var), b, varblock);
2373 assert(SCIPfindVar(scip, SCIPvarGetName(var)) != NULL);
2374 assert(SCIPvarIsActive(var));
2375 assert(varblock == b || varblock == GCGdecompGetNBlocks(decdecomp)+1);
2376 }
2377 }
2378
2379 /* check linking constraints and variables */
2380 for( v = 0; v < GCGdecompGetNLinkingvars(decdecomp); ++v )
2381 {
2382 int varblock;
2383 varblock = (int) (size_t) SCIPhashmapGetImage(GCGdecompGetVartoblock(decdecomp), GCGdecompGetLinkingvars(decdecomp)[v]); /*lint !e507*/
2384 assert( varblock == GCGdecompGetNBlocks(decdecomp) +1 || varblock == GCGdecompGetNBlocks(decdecomp)+2); /*lint !e507*/
2385 }
2386 for (c = 0; c < GCGdecompGetNLinkingconss(decdecomp); ++c)
2387 {
2388 assert(((int) (size_t) SCIPhashmapGetImage(GCGdecompGetConstoblock(decdecomp), GCGdecompGetLinkingconss(decdecomp)[c])) -1 == GCGdecompGetNBlocks(decdecomp)); /*lint !e507*/
2389 }
2390
2391 switch( GCGdecompGetType(decdecomp) )
2392 {
2394 assert(FALSE);
2395 break;
2397 assert(GCGdecompGetNLinkingvars(decdecomp) > 0 || GCGdecompGetNTotalStairlinkingvars(decdecomp) > 0);
2398 break;
2400 assert(GCGdecompGetNLinkingvars(decdecomp) == 0 && GCGdecompGetNLinkingconss(decdecomp) > 0);
2401 break;
2403 assert(GCGdecompGetNLinkingvars(decdecomp) == 0 && GCGdecompGetNLinkingconss(decdecomp) == 0);
2404 break;
2406 assert(GCGdecompGetNLinkingvars(decdecomp) > 0 && GCGdecompGetNLinkingconss(decdecomp) == 0);
2407 break;
2408 default:
2409 assert(FALSE);
2410 break;
2411 }
2412
2413#endif
2414 return SCIP_OKAY;
2415}
2416
2417/** creates a decomposition with all constraints in the master */
2419 GCG* gcg, /**< GCG data structure */
2420 GCG_DECOMP** decomp, /**< decomposition data structure */
2421 SCIP_Bool solveorigprob /**< is the original problem being solved? */
2422 )
2423{
2424 SCIP* scip;
2425 SCIP_HASHMAP* constoblock;
2426 SCIP_HASHMAP* vartoblock;
2427 SCIP_CONS** conss;
2428 SCIP_VAR** vars;
2429 SCIP_Bool haslinking;
2430 int nblocks;
2431 int nconss;
2432 int nvars;
2433 int c;
2434 int v;
2435
2436 assert(gcg != NULL);
2437 assert(decomp != NULL);
2438
2440 SCIP_CALL( GCGdecompCreate(gcg, decomp) );
2441 conss = SCIPgetConss(scip);
2442 nconss = SCIPgetNConss(scip);
2443 vars = SCIPgetVars(scip);
2444 nvars = SCIPgetNVars(scip);
2445
2446 SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(scip), nconss) );
2447 SCIP_CALL( SCIPhashmapCreate(&vartoblock, SCIPblkmem(scip), nvars) );
2448 haslinking = FALSE;
2449
2450
2451 for( c = 0; c < nconss; ++c )
2452 {
2453 if( GCGisConsGCGCons(conss[c]) )
2454 continue;
2455 SCIP_CALL( SCIPhashmapInsert(constoblock, conss[c], (void*) (size_t) 1 ) );
2456 }
2457
2458 for( v = 0; v < nvars; ++v )
2459 {
2460 SCIP_VAR* probvar = SCIPvarGetProbvar(vars[v]);
2461
2462 if( SCIPvarGetStatus(probvar) == SCIP_VARSTATUS_FIXED )
2463 continue;
2464 SCIP_CALL( SCIPhashmapInsert(vartoblock, probvar, (void*) (size_t) 1 ) );
2465 }
2466
2467 if( solveorigprob || SCIPgetNVars(scip) == 0 || SCIPgetNConss(scip) == 0 )
2468 nblocks = 0;
2469 else
2470 nblocks = 1;
2471
2472 GCGfilloutDecompFromHashmaps(gcg, *decomp, vartoblock, constoblock, nblocks, haslinking);
2473
2474 GCGdecompSetPresolved(*decomp, TRUE);
2475
2476 return SCIP_OKAY;
2477}
2478
2479/**
2480 * processes block representatives
2481 *
2482 * @return returns the number of blocks
2483 */
2484static
2486 int maxblock, /**< maximal number of blocks */
2487 int* blockrepresentative /**< array blockrepresentatives */
2488 )
2489{
2490 int i;
2491 int tempblock = 1;
2492
2493 assert(maxblock >= 1);
2494 assert(blockrepresentative != NULL );
2495 SCIPdebugPrintf("Blocks: ");
2496
2497 /* postprocess blockrepresentatives */
2498 for( i = 1; i < maxblock; ++i )
2499 {
2500 /* forward replace the representatives */
2501 assert(blockrepresentative[i] >= 0);
2502 assert(blockrepresentative[i] < maxblock);
2503 if( blockrepresentative[i] != i )
2504 blockrepresentative[i] = blockrepresentative[blockrepresentative[i]];
2505 else
2506 {
2507 blockrepresentative[i] = tempblock;
2508 ++tempblock;
2509 }
2510 /* It is crucial that this condition holds */
2511 assert(blockrepresentative[i] <= i);
2512 SCIPdebugPrintf("%d ", blockrepresentative[i]);
2513 }
2514 SCIPdebugPrintf("\n");
2515 return tempblock-1;
2516}
2517
2518/** */
2519static
2521 GCG* gcg, /**< GCG data structure */
2522 SCIP_CONS** conss, /**< array of all constraints */
2523 int nconss, /**< number of constraints */
2524 SCIP_Bool* consismaster, /**< array of flags whether a constraint belongs to the master problem */
2525 SCIP_HASHMAP* constoblock, /**< hashmap from constraints to block numbers, to be filled */
2526 int* vartoblock, /**< array mapping variables to block numbers, initially all -1, to be set */
2527 int* nextblock, /**< index of next free block to which no constraints have been assigned yet */
2528 int* blockrepresentative /**< array of blockrepresentatives */
2529 )
2530{
2531 SCIP* scip;
2532 int i;
2533 int j;
2534 SCIP_VAR** curvars;
2535 int ncurvars;
2536
2538 conss = SCIPgetConss(scip);
2539 nconss = SCIPgetNConss(scip);
2540
2541 /* go through the all constraints */
2542 for( i = 0; i < nconss; ++i )
2543 {
2544 int consblock;
2545 SCIP_CONS* cons = conss[i];
2546
2547 assert(cons != NULL);
2548 if( GCGisConsGCGCons(cons) )
2549 continue;
2550
2551 if( consismaster[i] )
2552 continue;
2553
2554 /* get variables of constraint; ignore empty constraints */
2555 ncurvars = GCGconsGetNVars(scip, cons);
2556 curvars = NULL;
2557 if( ncurvars > 0 )
2558 {
2559 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
2560 SCIP_CALL( GCGconsGetVars(scip, cons, curvars, ncurvars) );
2561 }
2562 assert(ncurvars >= 0);
2563 assert(ncurvars <= SCIPgetNVars(scip));
2564 assert(curvars != NULL || ncurvars == 0);
2565
2566 assert(SCIPhashmapGetImage(constoblock, cons) == NULL);
2567
2568 /* if there are no variables, put it in the first block, otherwise put it in the next block */
2569 if( ncurvars == 0 )
2570 consblock = -1;
2571 else
2572 consblock = *nextblock;
2573
2574 /* go through all variables */
2575 for( j = 0; j < ncurvars; ++j )
2576 {
2577 SCIP_VAR* probvar;
2578 int varindex;
2579 int varblock;
2580
2581 assert(curvars != NULL);
2582 probvar = SCIPvarGetProbvar(curvars[j]);
2583 assert(probvar != NULL);
2584
2585 /* ignore variables which have been fixed during presolving */
2586 if( SCIPvarGetStatus(probvar) == SCIP_VARSTATUS_FIXED )
2587 continue;
2588
2589 varindex = SCIPvarGetProbindex(probvar);
2590 assert(varindex >= 0);
2591 assert(varindex < SCIPgetNVars(scip));
2592
2593 /** @todo what about deleted variables? */
2594 /* get block of variable */
2595 varblock = vartoblock[varindex];
2596
2597 SCIPdebugMessage("\tVar %s (%d): ", SCIPvarGetName(probvar), varblock);
2598 /* if variable is already assigned to a block, assign constraint to that block */
2599 if( varblock > -1 && varblock != consblock )
2600 {
2601 consblock = MIN(consblock, blockrepresentative[varblock]);
2602 SCIPdebugPrintf("still in block %d.\n", varblock);
2603 }
2604 else if( varblock == -1 )
2605 {
2606 /* if variable is free, assign it to the new block for this constraint */
2607 varblock = consblock;
2608 assert(varblock > 0);
2609 assert(varblock <= *nextblock);
2610 vartoblock[varindex] = varblock;
2611 SCIPdebugPrintf("new in block %d.\n", varblock);
2612 }
2613 else
2614 {
2615 assert((varblock > 0) && (consblock == varblock));
2616 SCIPdebugPrintf("no change.\n");
2617 }
2618
2619 SCIPdebugPrintf("VARINDEX: %d (%d)\n", varindex, vartoblock[varindex]);
2620 }
2621
2622 /* if the constraint belongs to a new block, mark it as such */
2623 if( consblock == *nextblock )
2624 {
2625 assert(consblock > 0);
2626 blockrepresentative[consblock] = consblock;
2627 assert(blockrepresentative[consblock] > 0);
2628 assert(blockrepresentative[consblock] <= *nextblock);
2629 ++(*nextblock);
2630 }
2631
2632 SCIPdebugMessage("Cons %s will be in block %d (next %d)\n", SCIPconsGetName(cons), consblock, *nextblock);
2633
2634 for( j = 0; j < ncurvars; ++j )
2635 {
2636 SCIP_VAR* probvar;
2637 int varindex;
2638 int oldblock;
2639
2640 assert(curvars != NULL);
2641 probvar = SCIPvarGetProbvar(curvars[j]);
2642 assert(probvar != NULL);
2643
2644 /* ignore variables which have been fixed during presolving */
2645 if( SCIPvarGetStatus(probvar) == SCIP_VARSTATUS_FIXED )
2646 continue;
2647
2648 varindex = SCIPvarGetProbindex(probvar);
2649 assert(varindex >= 0);
2650 assert(varindex < SCIPgetNVars(scip));
2651
2652 oldblock = vartoblock[varindex];
2653 assert((oldblock > 0) && (oldblock <= *nextblock));
2654
2655 SCIPdebugMessage("\tVar %s ", SCIPvarGetName(probvar));
2656 if( oldblock != consblock )
2657 {
2658 SCIPdebugPrintf("reset from %d to block %d.\n", oldblock, consblock);
2659 vartoblock[varindex] = consblock;
2660 SCIPdebugPrintf("VARINDEX: %d (%d)\n", varindex, consblock);
2661
2662 if( (blockrepresentative[oldblock] != -1) && (blockrepresentative[oldblock] > blockrepresentative[consblock]) )
2663 {
2664 int oldrepr;
2665 oldrepr = blockrepresentative[oldblock];
2666 SCIPdebugMessage("\t\tBlock representative from block %d changed from %d to %d.\n", oldblock, blockrepresentative[oldblock], consblock);
2667 assert(consblock > 0);
2668 blockrepresentative[oldblock] = consblock;
2669 if( (oldrepr != consblock) && (oldrepr != oldblock) )
2670 {
2671 blockrepresentative[oldrepr] = consblock;
2672 SCIPdebugMessage("\t\tBlock representative from block %d changed from %d to %d.\n", oldrepr, blockrepresentative[oldrepr], consblock);
2673 }
2674 }
2675 }
2676 else
2677 {
2678 SCIPdebugPrintf("will not be changed from %d to %d.\n", oldblock, consblock);
2679 }
2680 }
2681
2682 SCIPfreeBufferArrayNull(scip, &curvars);
2683 assert(consblock >= 1 || consblock == -1);
2684 assert(consblock <= *nextblock);
2685
2686 /* store the constraint block */
2687 if( consblock != -1 )
2688 {
2689 SCIPdebugMessage("cons %s in block %d\n", SCIPconsGetName(cons), consblock);
2690 SCIP_CALL( SCIPhashmapInsert(constoblock, cons, (void*)(size_t)consblock) );
2691 }
2692 else
2693 {
2694 SCIPdebugMessage("ignoring %s\n", SCIPconsGetName(cons));
2695 }
2696 }
2697
2698 return SCIP_OKAY;
2699}
2700
2701/** */
2702static
2704 SCIP_CONS** conss, /**< array of all constraints */
2705 int nconss, /**< number of constraints */
2706 SCIP_Bool* consismaster, /**< array of flags whether a constraint belongs to the master problem */
2707 int nblocks, /**< number of blocks */
2708 SCIP_HASHMAP* constoblock, /**< current hashmap from constraints to block numbers */
2709 SCIP_HASHMAP* newconstoblock, /**< new hashmap from constraints to block numbers, to be filled */
2710 int* blockrepresentative /**< array of blockrepresentatives */
2711 )
2712{
2713 int i;
2714
2715 /* convert temporary data to detectordata */
2716 for( i = 0; i < nconss; ++i )
2717 {
2718 int consblock;
2719
2720 SCIP_CONS* cons = conss[i];
2721
2722 if( GCGisConsGCGCons(cons) )
2723 continue;
2724
2725 if( consismaster[i] )
2726 {
2727 SCIP_CALL( SCIPhashmapInsert(newconstoblock, cons, (void*) (size_t) (nblocks+1)) );
2728 continue;
2729 }
2730
2731 if( !SCIPhashmapExists(constoblock, cons) )
2732 continue;
2733
2734 consblock = (int) (size_t) SCIPhashmapGetImage(constoblock, cons); /*lint !e507*/
2735 assert(consblock > 0);
2736 consblock = blockrepresentative[consblock];
2737 assert(consblock <= nblocks);
2738 SCIP_CALL( SCIPhashmapInsert(newconstoblock, cons, (void*)(size_t)consblock) );
2739 SCIPdebugMessage("%d %s\n", consblock, SCIPconsGetName(cons));
2740 }
2741 return SCIP_OKAY;
2742}
2743
2744/** creates a decomposition with provided constraints in the master
2745 * The function will put the remaining constraints in one or more pricing problems
2746 * depending on whether the subproblems decompose with no variables in common.
2747 */
2749 GCG* gcg, /**< GCG data structure */
2750 GCG_DECOMP** decomp, /**< decomposition data structure */
2751 SCIP_CONS** masterconss, /**< constraints to be put in the master */
2752 int nmasterconss /**< number of constraints in the master */
2753 )
2754{
2755 SCIP* scip;
2756 SCIP_HASHMAP* constoblock;
2757 SCIP_HASHMAP* newconstoblock;
2758 SCIP_CONS** conss;
2759 int nconss;
2760 int nvars;
2761 int nblocks;
2762 int* blockrepresentative;
2763 int nextblock = 1;
2764 SCIP_Bool* consismaster;
2765 int i;
2766 int* vartoblock;
2767
2768 assert(gcg != NULL);
2769 assert(decomp != NULL);
2770 assert(nmasterconss == 0 || masterconss != NULL);
2771
2773 conss = SCIPgetConss(scip);
2774 nconss = SCIPgetNConss(scip);
2775 nvars = SCIPgetNVars(scip);
2776
2778
2779 assert( nmasterconss <= nconss );
2780
2781 if( GCGisConsGCGCons(conss[nconss-1]) )
2782 --nconss;
2783
2784 nblocks = nconss-nmasterconss+1;
2785 assert(nblocks > 0);
2786
2787 SCIP_CALL( SCIPallocBufferArray(scip, &blockrepresentative, nblocks) );
2788 SCIP_CALL( SCIPallocBufferArray(scip, &consismaster, nconss) );
2789 SCIP_CALL( SCIPallocBufferArray(scip, &vartoblock, nvars) );
2790 SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(scip), nconss) );
2791 SCIP_CALL( SCIPhashmapCreate(&newconstoblock, SCIPblkmem(scip), nconss) );
2792
2793 for( i = 0; i < nmasterconss; ++i )
2794 {
2795 SCIP_CALL( SCIPhashmapInsert(constoblock, masterconss[i], (void*) (size_t) (nblocks+1)) );
2796 }
2797
2798 for( i = 0; i < nconss; ++i )
2799 {
2800 assert(!GCGisConsGCGCons(conss[i]));
2801 consismaster[i] = SCIPhashmapExists(constoblock, conss[i]);
2802 }
2803
2804 for( i = 0; i < nvars; ++i )
2805 {
2806 vartoblock[i] = -1;
2807 }
2808
2809 for( i = 0; i < nblocks; ++i )
2810 {
2811 blockrepresentative[i] = -1;
2812 }
2813
2814 SCIP_CALL( assignConstraintsToRepresentatives(gcg, conss, nconss, consismaster, constoblock, vartoblock, &nextblock, blockrepresentative) );
2815
2816 /* postprocess blockrepresentatives */
2817 nblocks = processBlockRepresentatives(nextblock, blockrepresentative);
2818
2819 /* convert temporary data to detectordata */
2820 SCIP_CALL( fillConstoblock(conss, nconss, consismaster, nblocks, constoblock, newconstoblock, blockrepresentative) );
2821 SCIP_CALL( GCGdecompCreate(gcg, decomp) );
2822 SCIP_CALL( GCGfilloutDecompFromConstoblock(gcg, *decomp, newconstoblock, nblocks, FALSE) );
2823
2824 SCIPfreeBufferArray(scip, &vartoblock);
2825 SCIPfreeBufferArray(scip, &consismaster);
2826 SCIPfreeBufferArray(scip, &blockrepresentative);
2827 SCIPhashmapFree(&constoblock);
2828
2829 return SCIP_OKAY;
2830}
2831
2832/** increase the corresponding count of the variable stats*/
2833static
2835 SCIP_VAR* var, /**< variable to consider */
2836 int* nbinvars, /**< pointer to array of size nproblems to store number of binary subproblem vars */
2837 int* nintvars, /**< pointer to array of size nproblems to store number of integer subproblem vars */
2838 int* nimplvars, /**< pointer to array of size nproblems to store number of implied subproblem vars */
2839 int* ncontvars, /**< pointer to array of size nproblems to store number of continues subproblem vars */
2840 int nproblems, /**< size of the arrays*/
2841 int i /**< index of the array to increase */
2842)
2843{
2844 assert(var != NULL);
2845 assert(i >= 0);
2846 assert(i < nproblems);
2847
2848 if( nbinvars != NULL && (SCIPvarGetType(var) == SCIP_VARTYPE_BINARY || SCIPvarIsBinary(var)) )
2849 {
2850 ++(nbinvars[i]);
2851 assert(nbinvars[i] > 0);
2852 }
2853 if( nintvars != NULL && (SCIPvarGetType(var) == SCIP_VARTYPE_INTEGER && !SCIPvarIsBinary(var)) )
2854 {
2855 ++(nintvars[i]);
2856 assert(nintvars[i] > 0);
2857 }
2858 if( nimplvars != NULL && (SCIPvarGetImplType(var) != SCIP_IMPLINTTYPE_NONE) )
2859 {
2860 ++(nimplvars[i]);
2861 assert(nimplvars[i] > 0);
2862 }
2863 if( ncontvars != NULL && (SCIPvarGetType(var) == SCIP_VARTYPE_CONTINUOUS) )
2864 {
2865 ++(ncontvars[i]);
2866 assert(ncontvars[i] > 0);
2867 }
2868}
2869
2870/* score methods */
2871
2872/** return the number of variables and binary, integer, implied integer, continuous variables of all subproblems */
2874 GCG* gcg, /**< GCG data structure */
2875 GCG_DECOMP* decomp, /**< decomposition data structure */
2876 int* nvars, /**< pointer to array of size nproblems to store number of subproblem vars or NULL */
2877 int* nbinvars, /**< pointer to array of size nproblems to store number of binary subproblem vars or NULL */
2878 int* nintvars, /**< pointer to array of size nproblems to store number of integer subproblem vars or NULL */
2879 int* nimplvars, /**< pointer to array of size nproblems to store number of implied subproblem vars or NULL */
2880 int* ncontvars, /**< pointer to array of size nproblems to store number of continuous subproblem vars or NULL */
2881 int nproblems /**< size of the arrays*/
2882)
2883{
2884 int i;
2885 int j;
2886
2887 assert(gcg != NULL);
2888 assert(decomp != NULL);
2889 assert(nproblems > 0);
2890
2891 assert(GCGdecompGetType(decomp) != GCG_DECTYPE_UNKNOWN);
2892 if( nvars != NULL )
2893 BMSclearMemoryArray(nvars, nproblems);
2894 if( nbinvars != NULL )
2895 BMSclearMemoryArray(nbinvars, nproblems);
2896 if( nintvars != NULL )
2897 BMSclearMemoryArray(nintvars, nproblems);
2898 if( nimplvars != NULL )
2899 BMSclearMemoryArray(nimplvars, nproblems);
2900 if( ncontvars != NULL )
2901 BMSclearMemoryArray(ncontvars, nproblems);
2902
2903 for( i = 0; i < nproblems; ++i )
2904 {
2905 SCIP_VAR*** subscipvars;
2906 int* nsubscipvars;
2907
2908 nsubscipvars = GCGdecompGetNSubscipvars(decomp);
2909 subscipvars = GCGdecompGetSubscipvars(decomp);
2910 if( nvars != NULL )
2911 nvars[i] = nsubscipvars[i];
2912
2913 for( j = 0; j < nsubscipvars[i]; ++j )
2914 {
2915 incVarsData(subscipvars[i][j], nbinvars, nintvars, nimplvars, ncontvars, nproblems, i);
2916 }
2917 }
2918}
2919
2920
2921/** return the number of variables and binary, integer, implied integer, continuous variables of the master */
2923 GCG* gcg, /**< GCG data structure */
2924 GCG_DECOMP* decomp, /**< decomposition data structure */
2925 int* nvars, /**< pointer to store number of linking vars or NULL */
2926 int* nbinvars, /**< pointer to store number of binary linking vars or NULL */
2927 int* nintvars, /**< pointer to store number of integer linking vars or NULL */
2928 int* nimplvars, /**< pointer to store number of implied linking vars or NULL */
2929 int* ncontvars /**< pointer to store number of continuous linking vars or NULL */
2930)
2931{
2932 int i;
2933 SCIP_VAR** linkingvars;
2934 int nlinkingvars;
2935
2936 assert(gcg != NULL);
2937 assert(decomp != NULL);
2938
2939 assert(GCGdecompGetType(decomp) != GCG_DECTYPE_UNKNOWN);
2940
2941 nlinkingvars = GCGdecompGetNLinkingvars(decomp);
2942 linkingvars = GCGdecompGetLinkingvars(decomp);
2943
2944 if( nvars != NULL )
2945 *nvars = nlinkingvars;
2946 if( nbinvars != NULL )
2947 *nbinvars = 0;
2948 if( nintvars != NULL )
2949 *nintvars = 0;
2950 if( nimplvars != NULL )
2951 *nimplvars = 0;
2952 if( ncontvars != NULL )
2953 *ncontvars = 0;
2954
2955
2956 for( i = 0; i < nlinkingvars; ++i )
2957 {
2958 incVarsData(linkingvars[i], nbinvars, nintvars, nimplvars, ncontvars, 1, 0);
2959 }
2960}
2961
2962/**
2963 * returns the number of nonzeros of each column of the constraint matrix both in the subproblem and in the master
2964 * @note For linking variables, the number of nonzeros in the subproblems corresponds to the number on nonzeros
2965 * in the border
2966 *
2967 * @note The arrays have to be allocated by the caller
2968 *
2969 * @pre This function assumes that constraints are partitioned in the decomp structure, no constraint is present in more than one block
2970 *
2971 */
2973 GCG* gcg, /**< GCG data structure */
2974 GCG_DECOMP* decomp, /**< decomposition data structure */
2975 SCIP_VAR** vars, /**< pointer to array store variables belonging to density */
2976 int nvars, /**< number of variables */
2977 SCIP_CONS** conss, /**< pointer to array to store constraints belonging to the density */
2978 int nconss, /**< number of constraints */
2979 int* varsubproblemdensity, /**< pointer to array to store the nonzeros for the subproblems */
2980 int* varmasterdensity, /**< pointer to array to store the nonzeros for the master */
2981 int* conssubproblemdensity, /**< pointer to array to store the nonzeros for the subproblems */
2982 int* consmasterdensity /**< pointer to array to store the nonzeros for the master */
2983)
2984{
2985 SCIP* scip;
2986 int nlinkingconss;
2987 SCIP_HASHMAP* vartoblock;
2988 SCIP_CONS** curconss;
2989
2990 int ncurvars;
2991 SCIP_VAR** curvars;
2992 SCIP_Bool success;
2993
2994 int i;
2995 int j;
2996 int v;
2997 int c;
2998
2999 assert(gcg != NULL);
3000 assert(decomp != NULL);
3001 assert(vars != NULL);
3002 assert(nvars > 0);
3003 assert(conss != NULL);
3004 assert(varsubproblemdensity != NULL);
3005 assert(varmasterdensity != NULL);
3006 assert(conssubproblemdensity != NULL);
3007 assert(consmasterdensity != NULL);
3008
3010
3011 /* make sure the passed data is initialised to 0 */
3012 BMSclearMemoryArray(vars, nvars);
3013 BMSclearMemoryArray(conss, nconss);
3014 BMSclearMemoryArray(varsubproblemdensity, nvars);
3015 BMSclearMemoryArray(varmasterdensity, nvars);
3016 BMSclearMemoryArray(conssubproblemdensity, nconss);
3017 BMSclearMemoryArray(consmasterdensity, nconss);
3018
3019 BMScopyMemoryArray(vars, SCIPgetVars(scip), nvars);
3020
3021 vartoblock = GCGdecompGetVartoblock(decomp);
3022 c = 0;
3023 for( i = 0; i < GCGdecompGetNBlocks(decomp); ++i )
3024 {
3025 curconss = GCGdecompGetSubscipconss(decomp)[i];
3026 assert(curconss != NULL);
3027
3028 for( j = 0; j < GCGdecompGetNSubscipconss(decomp)[i]; ++j )
3029 {
3030 assert(c < nconss); /* This assertion and the logic forbids constraints in more than one block */
3031 conss[c] = curconss[j];
3032
3033 SCIP_CALL( SCIPgetConsNVars(scip, curconss[j], &ncurvars, &success) );
3034 assert(success);
3035 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
3036 SCIP_CALL( SCIPgetConsVars(scip, curconss[j], curvars, ncurvars, &success) );
3037 assert(success);
3038
3039 for( v = 0; v < ncurvars; ++v )
3040 {
3041 SCIP_VAR* var;
3042 int block;
3043 int probindex;
3044
3045 var = curvars[v];
3046 var = SCIPvarGetProbvar(var);
3047 probindex = SCIPvarGetProbindex(var);
3048
3050 continue;
3051
3052 assert(probindex >= 0);
3053 assert(probindex < nvars);
3054 varsubproblemdensity[probindex] += 1;
3055 assert(varsubproblemdensity[probindex] > 0);
3056 block = (int) (size_t) SCIPhashmapGetImage(vartoblock, var); /*lint !e507*/
3057 assert(block > 0);
3058
3059 if( block <= GCGdecompGetNBlocks(decomp) )
3060 {
3061 conssubproblemdensity[c] +=1;
3062 }
3063 else
3064 {
3065 consmasterdensity[c] += 1;
3066 }
3067 }
3068
3069 SCIPfreeBufferArray(scip, &curvars);
3070 c++;
3071 }
3072 }
3073
3074 nlinkingconss = GCGdecompGetNLinkingconss(decomp);
3075 curconss = GCGdecompGetLinkingconss(decomp);
3076
3077 for( j = 0; j < nlinkingconss; ++j )
3078 {
3079 assert(c < nconss); /* This assertion and the logic forbids constraints in more than one block */
3080 SCIP_CALL( SCIPgetConsNVars(scip, curconss[j], &ncurvars, &success) );
3081 assert(success);
3082 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
3083 SCIP_CALL( SCIPgetConsVars(scip, curconss[j], curvars, ncurvars, &success) );
3084 assert(success);
3085
3086 conss[c] = curconss[j];
3087
3088 for( v = 0; v < ncurvars; ++v )
3089 {
3090 SCIP_VAR* var;
3091 int probindex;
3092
3093 var = curvars[v];
3094 var = SCIPvarGetProbvar(var);
3095 probindex = SCIPvarGetProbindex(var);
3096
3098 continue;
3099
3100 assert(probindex >= 0);
3101 assert(probindex < nvars);
3102 varmasterdensity[probindex] += 1;
3103 assert(varmasterdensity[probindex] > 0);
3104 SCIPdebugMessage("Var <%s> appears in cons <%s>, total count: %d\n", SCIPvarGetName(var), SCIPconsGetName(curconss[j]), varmasterdensity[probindex]);
3105 }
3106
3107 consmasterdensity[c] = ncurvars;
3108 c++;
3109
3110 SCIPfreeBufferArray(scip, &curvars);
3111 }
3112
3113 return SCIP_OKAY;
3114}
3115
3116/** helper function to increase correct lock */
3117static
3119 GCG* gcg, /**< GCG data structure */
3120 SCIP_Real lhs, /**< left side of constraint */
3121 SCIP_Real coef, /**< coefficient of variable in constraint */
3122 SCIP_Real rhs, /**< right side of constraint */
3123 int* downlock, /**< pointer to store downlock */
3124 int* uplock /**< pointer to store uplock */
3125 )
3126{
3127 SCIP* scip;
3128 assert(gcg != NULL);
3129 assert(downlock != NULL);
3130 assert(uplock != NULL);
3131
3133 if( !SCIPisInfinity(scip, -lhs) )
3134 {
3135 if( SCIPisPositive(scip, coef) )
3136 ++(*downlock);
3137 if( SCIPisNegative(scip, coef) )
3138 ++(*uplock);
3139
3140 }
3141 if( !SCIPisInfinity(scip, rhs) )
3142 {
3143 if( SCIPisPositive(scip, coef) )
3144 ++(*uplock);
3145 if( SCIPisNegative(scip, coef) )
3146 ++(*downlock);
3147 }
3148
3149}
3150
3151/**
3152 * calculates the number of up and down locks of variables for a given decomposition in both the original problem and the pricingproblems
3153 *
3154 * @note All arrays need to be allocated by the caller
3155 *
3156 * @warning This function needs a lot of memory (nvars*nblocks+1) array entries
3157 */
3159 GCG* gcg, /**< GCG data structure */
3160 GCG_DECOMP* decomp, /**< decomposition data structure */
3161 SCIP_VAR** vars, /**< pointer to array store variables belonging to density */
3162 int nvars, /**< number of variables */
3163 int nsubproblems, /**< number of sub problems */
3164 int** subsciplocksdown, /**< pointer to two dimensional array to store the down locks for the subproblems */
3165 int** subsciplocksup, /**< pointer to two dimensional array to store the down locks for the subproblems */
3166 int* masterlocksdown, /**< pointer to array to store the down locks for the master */
3167 int* masterlocksup /**< pointer to array to store the down locks for the master */
3168 )
3169{
3170 SCIP* scip;
3171 int nlinkingconss;
3172 SCIP_CONS** curconss;
3173 SCIP_VAR** curvars;
3174 SCIP_Real* curvals;
3175 int ncurvars;
3176 SCIP_Real lhs;
3177 SCIP_Real rhs;
3178
3179 SCIP_Bool success;
3180
3181 int i;
3182 int j;
3183 int v;
3184
3185 assert(gcg != NULL);
3187 assert(decomp != NULL);
3188 assert(vars != NULL);
3189 assert(nvars > 0);
3190 assert(nvars == SCIPgetNVars(scip));
3191 assert(subsciplocksdown != NULL);
3192 assert(subsciplocksup != NULL);
3193 assert(masterlocksdown != NULL);
3194 assert(masterlocksup != NULL);
3195
3196 /* make sure the passed data is initialised to 0 */
3197 BMSclearMemoryArray(vars, nvars);
3198 BMScopyMemoryArray(vars, SCIPgetVars(scip), nvars);
3199 BMSclearMemoryArray(masterlocksdown, nvars);
3200 BMSclearMemoryArray(masterlocksup, nvars);
3201 for( i = 0; i < nsubproblems; ++i )
3202 {
3203 BMSclearMemoryArray(subsciplocksdown[i], nvars); /*lint !e866*/
3204 BMSclearMemoryArray(subsciplocksup[i], nvars); /*lint !e866*/
3205 }
3206
3207 for( i = 0; i < GCGdecompGetNBlocks(decomp); ++i )
3208 {
3209 curconss = GCGdecompGetSubscipconss(decomp)[i];
3210 assert(curconss != NULL);
3211
3212 for( j = 0; j < GCGdecompGetNSubscipconss(decomp)[i]; ++j )
3213 {
3214
3215 SCIP_CALL( SCIPgetConsNVars(scip, curconss[j], &ncurvars, &success) );
3216 assert(success);
3217 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
3218 SCIP_CALL( SCIPallocBufferArray(scip, &curvals, ncurvars) );
3219
3220 SCIP_CALL( GCGconsGetVals(scip, curconss[j], curvals, ncurvars) );
3221 SCIP_CALL( SCIPgetConsVars(scip, curconss[j], curvars, ncurvars, &success) );
3222 assert(success);
3223
3224 rhs = GCGconsGetRhs(scip, curconss[j]);
3225 lhs = GCGconsGetLhs(scip, curconss[j]);
3226
3227 for( v = 0; v < ncurvars; ++v )
3228 {
3229 SCIP_VAR* var;
3230 int probindex;
3231
3232 var = curvars[v];
3233 var = SCIPvarGetProbvar(var);
3234 probindex = SCIPvarGetProbindex(var);
3235
3237 continue;
3238
3239 assert(probindex >= 0);
3240 assert(probindex < nvars);
3241 assert(SCIPhashmapExists(GCGdecompGetVartoblock(decomp), var));
3242
3243 increaseLock(gcg, lhs, curvals[v], rhs, &(subsciplocksdown[i][probindex]), &(subsciplocksup[i][probindex]));
3244 }
3245
3246 SCIPfreeBufferArray(scip, &curvals);
3247 SCIPfreeBufferArray(scip, &curvars);
3248 }
3249 }
3250
3251 nlinkingconss = GCGdecompGetNLinkingvars(decomp);
3252 curconss = GCGdecompGetLinkingconss(decomp);
3253 for( j = 0; j < nlinkingconss; ++j )
3254 {
3255 SCIP_CALL( SCIPgetConsNVars(scip, curconss[j], &ncurvars, &success) );
3256 assert(success);
3257 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
3258 SCIP_CALL( SCIPallocBufferArray(scip, &curvals, ncurvars) );
3259
3260 SCIP_CALL( GCGconsGetVals(scip, curconss[j], curvals, ncurvars) );
3261 SCIP_CALL( SCIPgetConsVars(scip, curconss[j], curvars, ncurvars, &success) );
3262 assert(success);
3263
3264 rhs = GCGconsGetRhs(scip, curconss[j]);
3265 lhs = GCGconsGetLhs(scip, curconss[j]);
3266
3267 for( v = 0; v < ncurvars; ++v )
3268 {
3269 SCIP_VAR* var;
3270 int probindex;
3271
3272 var = curvars[v];
3273 var = SCIPvarGetProbvar(var);
3274 probindex = SCIPvarGetProbindex(var);
3275
3277 continue;
3278
3279 assert(probindex >= 0);
3280 assert(probindex < nvars);
3281
3282 increaseLock(gcg, lhs, curvals[v], rhs, &(masterlocksdown[probindex]), &(masterlocksup[probindex]));
3283 }
3284
3285 SCIPfreeBufferArray(scip, &curvals);
3286 SCIPfreeBufferArray(scip, &curvars);
3287 }
3288
3289 return SCIP_OKAY;
3290}
3291
3292
3293/** sets the score of the given decomposition based on the border, the average density score and the ratio of
3294 * linking variables
3295 */
3297 GCG* gcg, /**< GCG data structure */
3298 GCG_DECOMP* decdecomp, /**< decomposition data structure */
3299 SCIP_Real maxwhitescore /**< score related to max white measure (i.e. fraction of white (nonblock and nonborder) matrix area ) */
3300 )
3301{
3302 assert(maxwhitescore >= 0);
3303
3304 decdecomp->maxwhitescore = maxwhitescore;
3305
3306 return;
3307}
3308
3309
3310/** computes the score of the given decomposition based on the border, the average density score and the ratio of
3311 * linking variables
3312 */
3314 GCG* gcg, /**< GCG data structure */
3315 GCG_DECOMP* decdecomp /**< decomposition data structure */
3316 )
3317{
3318 DEC_SCORES score;
3319
3320 if( decdecomp->maxwhitescore == -1.)
3321 GCGdecompEvaluateDecomposition(gcg, decdecomp, &score);
3322
3323 assert(decdecomp->maxwhitescore >= 0);
3324
3325 return decdecomp->maxwhitescore;
3326}
3327
3328/** computes the score of the given decomposition based on the border, the average density score and the ratio of
3329 * linking variables
3330 */
3332 GCG* gcg, /**< GCG data structure */
3333 GCG_DECOMP* decdecomp, /**< decomposition data structure */
3334 DEC_SCORES* score /**< returns the score of the decomposition */
3335 )
3336{
3337 SCIP* scip;
3338 SCIP_Longint matrixarea;
3339 SCIP_Longint borderarea;
3340 int nvars;
3341 int nconss;
3342 int i;
3343 int j;
3344 int k;
3345 /* int blockarea; */
3346 SCIP_Real varratio;
3347 int* nzblocks;
3348 int nblocks;
3349 int* nlinkvarsblocks;
3350 int* nvarsblocks;
3351 SCIP_Real* blockdensities;
3352 int* blocksizes;
3353 SCIP_Real density;
3354 SCIP_Real blackarea;
3355
3356 SCIP_Real alphaborderarea;
3357 SCIP_Real alphalinking;
3358 SCIP_Real alphadensity;
3359
3360 alphaborderarea = 0.6;
3361 alphalinking = 0.2 ;
3362 alphadensity = 0.2;
3363 blackarea = 0.;
3364
3365
3366 assert(gcg != NULL);
3367 assert(score != NULL);
3368
3370 nvars = SCIPgetNVars(scip);
3371 nconss = SCIPgetNConss(scip);
3372
3373 nblocks = GCGdecompGetNBlocks(decdecomp);
3374
3375 SCIP_CALL( SCIPallocBufferArray(scip, &nzblocks, nblocks) );
3376 SCIP_CALL( SCIPallocBufferArray(scip, &nlinkvarsblocks, nblocks) );
3377 SCIP_CALL( SCIPallocBufferArray(scip, &blockdensities, nblocks) );
3378 SCIP_CALL( SCIPallocBufferArray(scip, &blocksizes, nblocks) );
3379 SCIP_CALL( SCIPallocBufferArray(scip, &nvarsblocks, nblocks) );
3380 /*
3381 * 3 Scores
3382 *
3383 * - Area percentage (min)
3384 * - block density (max)
3385 * - \pi_b {v_b|v_b is linking}/#vb (min)
3386 */
3387
3388 /* calculate matrix area */
3389 matrixarea = (SCIP_Longint) nvars*nconss;
3390
3391 blackarea += ( GCGdecompGetNLinkingvars(decdecomp) - GCGdecompGetNMastervars(decdecomp) ) * nconss;
3392 blackarea += GCGdecompGetNLinkingconss(decdecomp) * nvars;
3393
3394 blackarea -= (GCGdecompGetNLinkingvars(decdecomp) - GCGdecompGetNMastervars(decdecomp) ) * GCGdecompGetNLinkingconss(decdecomp);
3395
3396
3397 /* calculate slave sizes, nonzeros and linkingvars */
3398 for( i = 0; i < nblocks; ++i )
3399 {
3400 SCIP_CONS** curconss;
3401 int ncurconss;
3402 int nvarsblock;
3403 SCIP_Bool *ishandled;
3404
3405 SCIP_CALL( SCIPallocBufferArray(scip, &ishandled, nvars) );
3406 nvarsblock = 0;
3407 nzblocks[i] = 0;
3408 nlinkvarsblocks[i] = 0;
3409 blackarea += GCGdecompGetNSubscipconss(decdecomp)[i] * ( GCGdecompGetNSubscipvars(decdecomp)[i] );
3410
3411 for( j = 0; j < nvars; ++j )
3412 {
3413 ishandled[j] = FALSE;
3414 }
3415 curconss = GCGdecompGetSubscipconss(decdecomp)[i];
3416 ncurconss = GCGdecompGetNSubscipconss(decdecomp)[i];
3417
3418 for( j = 0; j < ncurconss; ++j )
3419 {
3420 SCIP_VAR** curvars;
3421 SCIP_VAR* var;
3422 int ncurvars;
3423 ncurvars = GCGconsGetNVars(scip, curconss[j]);
3424 if ( ncurvars == 0 )
3425 continue;
3426 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
3427 SCIP_CALL( GCGconsGetVars(scip, curconss[j], curvars, ncurvars) );
3428
3429 for( k = 0; k < ncurvars; ++k )
3430 {
3431 int block;
3432 if( !GCGisVarRelevant(curvars[k]) )
3433 continue;
3434
3435 var = SCIPvarGetProbvar(curvars[k]);
3436 assert(var != NULL);
3437 if( !GCGisVarRelevant(var) )
3438 continue;
3439
3440 assert(SCIPvarIsActive(var));
3441 assert(!SCIPvarIsDeleted(var));
3442 ++(nzblocks[i]);
3443 if( !SCIPhashmapExists(GCGdecompGetVartoblock(decdecomp), var) )
3444 {
3445 block = (int)(size_t) SCIPhashmapGetImage(GCGdecompGetVartoblock(decdecomp), curvars[k]); /*lint !e507*/
3446 }
3447 else
3448 {
3449 assert(SCIPhashmapExists(GCGdecompGetVartoblock(decdecomp), var));
3450 block = (int)(size_t) SCIPhashmapGetImage(GCGdecompGetVartoblock(decdecomp), var); /*lint !e507*/
3451 }
3452
3453 if( block == nblocks+1 && ishandled[SCIPvarGetProbindex(var)] == FALSE )
3454 {
3455 ++(nlinkvarsblocks[i]);
3456 }
3457 ishandled[SCIPvarGetProbindex(var)] = TRUE;
3458 }
3459
3460 SCIPfreeBufferArray(scip, &curvars);
3461 }
3462
3463 for( j = 0; j < nvars; ++j )
3464 {
3465 if( ishandled[j] )
3466 {
3467 ++nvarsblock;
3468 }
3469 }
3470
3471 blocksizes[i] = nvarsblock*ncurconss;
3472 nvarsblocks[i] = nvarsblock;
3473 if( blocksizes[i] > 0 )
3474 {
3475 blockdensities[i] = 1.0*nzblocks[i]/blocksizes[i];
3476 }
3477 else
3478 {
3479 blockdensities[i] = 0.0;
3480 }
3481
3482 assert(blockdensities[i] >= 0 && blockdensities[i] <= 1.0);
3483 SCIPfreeBufferArray(scip, &ishandled);
3484 }
3485
3486 borderarea = (SCIP_Longint) GCGdecompGetNLinkingconss(decdecomp)*nvars + (SCIP_Longint) GCGdecompGetNLinkingvars(decdecomp)*(nconss-GCGdecompGetNLinkingconss(decdecomp));
3487
3488 density = 1E20;
3489 varratio = 1.0;
3490 for( i = 0; i < nblocks; ++i )
3491 {
3492 density = MIN(density, blockdensities[i]);
3493
3494 if( GCGdecompGetNLinkingvars(decdecomp) > 0 )
3495 {
3496 varratio *= 1.0*nlinkvarsblocks[i]/GCGdecompGetNLinkingvars(decdecomp);
3497 }
3498 else
3499 {
3500 varratio = 0;
3501 }
3502 }
3503
3504 score->linkingscore = (0.5+0.5*varratio);
3505 score->borderscore = (1.0*(borderarea)/matrixarea);
3506 score->densityscore = (1-density);
3507 //score->maxwhitescore = blackarea/( nconss * nvars );
3508
3509 //decdecomp->maxwhitescore = score->maxwhitescore;
3510
3511
3512 switch( GCGdecompGetType(decdecomp) )
3513 {
3515 score->totalscore = alphaborderarea*(score->borderscore) + alphalinking*(score->linkingscore) + alphadensity*(score->densityscore);
3516/* score->totalscore = score->borderscore*score->linkingscore*score->densityscore; */
3517 break;
3519 score->totalscore = alphaborderarea*(score->borderscore) + alphalinking*(score->linkingscore) + alphadensity*(score->densityscore);
3520 /* score->totalscore = score->borderscore*score->linkingscore*score->densityscore; */
3521 break;
3523 if(nblocks == 1 || nblocks == 0)
3524 score->totalscore = 1.0;
3525 else
3526 score->totalscore = 0.0;
3527 break;
3529 score->totalscore = alphaborderarea*(score->borderscore) + alphalinking*(score->linkingscore) + 0.2*(score->densityscore);
3530/* score->totalscore = score->borderscore*score->linkingscore*score->densityscore; */
3531 break;
3533 SCIPerrorMessage("Decomposition type is %s, cannot compute score\n", GCGdecompGetStrType(GCGdecompGetType(decdecomp)));
3534 assert(FALSE);
3535 break;
3536 default:
3537 SCIPerrorMessage("No rule for this decomposition type, cannot compute score\n");
3538 assert(FALSE);
3539 break;
3540 }
3541 if(nblocks == 1 || nblocks == 0)
3542 score->totalscore = 1.0;
3543
3544 if( nblocks == 0 || nblocks == 1)
3545 score->totalscore = 1;
3546
3547 SCIPfreeBufferArray(scip, &nvarsblocks);
3548 SCIPfreeBufferArray(scip, &blocksizes);
3549 SCIPfreeBufferArray(scip, &blockdensities);
3550 SCIPfreeBufferArray(scip, &nlinkvarsblocks);
3551 SCIPfreeBufferArray(scip, &nzblocks);
3552 return SCIP_OKAY;
3553}
3554
3555/** compute the density of variables in blocks and master */
3556static
3558 GCG* gcg, /**< GCG data structure */
3559 GCG_DECOMP* decomp, /**< decomposition data structure */
3560 int* varprobdensity, /**< density information */
3561 int* varmasterdensity, /**< density information */
3562 SCIP_VAR** vars, /**< array of variables */
3563 int nvars, /**< number of variables */
3564 DEC_STATISTIC* blockvardensities, /**< array of statistic structs to store density information of each block */
3565 DEC_STATISTIC* mastervardensity, /**< pointer to store density information of master variables*/
3566 int nblocks /**< number of blocks */
3567 )
3568{
3569 SCIP* scip;
3570 int v;
3571 int b;
3572 SCIP_Real** vardistribution;
3573 int* nvardistribution;
3574 SCIP_Real* mastervardistribution;
3575
3576 SCIP_Real max = 0;
3577 SCIP_Real min = 1.0;
3578 SCIP_Real median = 0;
3579 SCIP_Real mean = 0;
3580
3581 assert(gcg != NULL);
3582 assert(decomp != NULL);
3583
3584 assert(vars != NULL);
3585 assert(nvars > 0);
3586 assert(blockvardensities != NULL);
3587 assert(mastervardensity != NULL);
3588 assert(nblocks >= 0);
3589
3591 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &vardistribution, nblocks) );
3592 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &nvardistribution, nblocks) );
3593
3594 BMSclearMemoryArray(vardistribution, nblocks);
3595 BMSclearMemoryArray(nvardistribution, nblocks);
3596
3597 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &mastervardistribution, nvars) );
3598 BMSclearMemoryArray(mastervardistribution, nvars);
3599
3600 for( b = 0; b < nblocks; ++b )
3601 {
3602 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &vardistribution[b], GCGdecompGetNSubscipvars(decomp)[b]) ); /*lint !e866 !e666*/
3603 BMSclearMemoryArray(vardistribution[b], GCGdecompGetNSubscipvars(decomp)[b]); /*lint !e866 */
3604 }
3605
3606 for( v = 0; v < nvars; ++v )
3607 {
3608 int block = ((int) (size_t) SCIPhashmapGetImage(GCGdecompGetVartoblock(decomp), (vars[v]))) - 1; /*lint !e507 */
3609 assert(block >= 0);
3610 SCIPdebugMessage("Var <%s>:", SCIPvarGetName(vars[v]));
3611
3612
3613 mastervardistribution[v] = 1.0*varmasterdensity[v]/GCGdecompGetNLinkingconss(decomp);
3614 SCIPdebugPrintf("master %d ", varmasterdensity[v]);
3615
3616 if( block < nblocks )
3617 {
3618 vardistribution[block][nvardistribution[block]] = 1.0*varprobdensity[v]/GCGdecompGetNSubscipconss(decomp)[block];
3619 SCIPdebugPrintf("block %d %.3f\n", block, vardistribution[block][nvardistribution[block]]);
3620 ++(nvardistribution[block]);
3621 }
3622 else
3623 {
3624 SCIPdebugPrintf("\n");
3625 }
3626 }
3627
3628 for( b = 0; b < nblocks; ++b )
3629 {
3630 int ncurvars = GCGdecompGetNSubscipvars(decomp)[b];
3631
3632 max = 0;
3633 min = 1.0;
3634 median = 0;
3635 mean = 0;
3636
3637
3638
3639 SCIPdebugMessage("block %d:", b);
3640 for( v = 0; v < ncurvars; ++v )
3641 {
3642
3643 SCIPdebugPrintf(" <%s> %.3f", SCIPvarGetName(GCGdecompGetSubscipvars(decomp)[b][v]), vardistribution[b][v]);
3644 max = MAX(max, vardistribution[b][v]);
3645 min = MIN(min, vardistribution[b][v]);
3646 mean += 1.0*vardistribution[b][v]/ncurvars;
3647
3648 }
3649 if( ncurvars > 0 )
3650 median = quick_select_median(vardistribution[b], ncurvars);
3651
3652 SCIPdebugPrintf("\nmin: %.3f, max: %.3f, median: %.3f, mean: %.3f\n", min, max, median, mean);
3653
3654 blockvardensities[b].max = max;
3655 blockvardensities[b].min = min;
3656 blockvardensities[b].median = median;
3657 blockvardensities[b].mean = mean;
3658 }
3659 max = 0;
3660 min = 1.0;
3661 mean = 0;
3662
3663 SCIPdebugMessage("master:");
3664
3665 for( v = 0; v < nvars; ++v )
3666 {
3667
3668 SCIPdebugPrintf(" <%s> %.3f", SCIPvarGetName(vars[v]), mastervardistribution[v]);
3669 max = MAX(max, mastervardistribution[v]);
3670 min = MIN(min, mastervardistribution[v]);
3671 mean += 1.0*mastervardistribution[v]/nvars;
3672
3673 }
3674 median = quick_select_median(mastervardistribution, nvars);
3675 SCIPdebugPrintf("\nmin: %.3f, max: %.3f, median: %.3f, mean: %.3f\n", min, max, median, mean);
3676
3677
3678 mastervardensity->max = max;
3679 mastervardensity->min = min;
3680 mastervardensity->median = median;
3681 mastervardensity->mean = mean;
3682
3683 for( b = 0; b < nblocks; ++b )
3684 {
3685 SCIPfreeBlockMemoryArray(scip, &vardistribution[b], GCGdecompGetNSubscipvars(decomp)[b]); /*lint !e866 */
3686 }
3687
3688 SCIPfreeBlockMemoryArray(scip, &mastervardistribution, nvars);
3689
3690 SCIPfreeBlockMemoryArray(scip, &nvardistribution, nblocks);
3691 SCIPfreeBlockMemoryArray(scip, &vardistribution, nblocks);
3692
3693 return SCIP_OKAY;
3694}
3695
3696/** returns the number of constraints saved in the decomposition */
3698 GCG_DECOMP* decomp /**< decomposition data structure */
3699 )
3700{
3701 int b;
3702 int nconss = 0;
3703 assert(decomp != NULL);
3704
3705 for( b = 0; b < GCGdecompGetNBlocks(decomp); ++b )
3706 nconss += GCGdecompGetNSubscipconss(decomp)[b];
3707
3708 nconss += GCGdecompGetNLinkingconss(decomp);
3709 return nconss;
3710}
3711
3712/** computes nonzero elements of a given constraint, separated into linking variables and normal vars */
3713static
3715 GCG* gcg, /**< GCG data structure */
3716 GCG_DECOMP* decomp, /**< decomposition data structure */
3717 SCIP_CONS* cons, /**< SCIP data structure */
3718 int* nzeros, /**< pointer to store nonzero elements */
3719 int* nintzeros, /**< pointer to store integer nonzeros */
3720 int* nbzeros, /**< pointer to store border nonzero elements */
3721 int* nintbzeros /**< pointer to store border integer nonzeros */
3722)
3723{
3724 SCIP* scip;
3725 int v;
3726 int ncurvars;
3727 SCIP_VAR** curvars = NULL;
3728 SCIP_Real* curvals = NULL;
3729
3730 assert(gcg != NULL);
3731 assert(decomp != NULL);
3732 assert(cons != NULL);
3733 assert(nzeros != NULL);
3734 assert(nintzeros != NULL);
3735 assert(nbzeros != NULL);
3736 assert(nintbzeros != NULL);
3737
3739 ncurvars = GCGconsGetNVars(scip, cons);
3740 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
3741 SCIP_CALL( SCIPallocBufferArray(scip, &curvals, ncurvars) );
3742
3743 SCIP_CALL( GCGconsGetVars(scip, cons, curvars, ncurvars) );
3744 SCIP_CALL( GCGconsGetVals(scip, cons, curvals, ncurvars) );
3745
3746 for( v = 0; v < ncurvars; ++v )
3747 {
3748 int block;
3749 SCIP_VAR* curvar;
3750 if( SCIPisZero(scip, curvals[v]) )
3751 continue;
3752
3753 curvar = SCIPvarGetProbvar(curvars[v]);
3754
3755 if( SCIPvarGetStatus(curvar) == SCIP_VARSTATUS_FIXED )
3756 continue;
3757
3758 block = ((int) (size_t) SCIPhashmapGetImage(GCGdecompGetVartoblock(decomp), (curvar))) - 1; /*lint !e507 */
3759 assert(block >= 0);
3760
3761 if( block > GCGdecompGetNBlocks(decomp) )
3762 {
3764 *nintbzeros += 1;
3765
3766 *nbzeros += 1;
3767 }
3768 else
3769 {
3771 *nintzeros += 1;
3772
3773 *nzeros += 1;
3774 }
3775 }
3776
3777 SCIPfreeBufferArrayNull(scip, &curvals);
3778 SCIPfreeBufferArrayNull(scip, &curvars);
3779
3780 return SCIP_OKAY;
3781}
3782
3783/** computes nonzero elements of the pricing problems and the master */
3784static
3786 GCG* gcg, /**< GCG data structure */
3787 GCG_DECOMP* decomp, /**< decomposition data structure */
3788 int* mnzeros, /**< number of nonzero elements in row border */
3789 int* mintnzeros, /**< number of integral nonzero elements in row border */
3790 int* lnzeros, /**< number of nonzero elements in column border */
3791 int* lintnzeros, /**< number of integral nonzero elements in column border */
3792 int* nonzeros, /**< number of nonzero elements per pricing problem */
3793 int* intnzeros /**< number of integral nonzero elements per pricing problem */
3794 )
3795{
3796 int c;
3797 int b;
3798
3799 assert(gcg != NULL);
3800 assert(decomp != NULL);
3801 assert(mnzeros != NULL);
3802 assert(mintnzeros != NULL);
3803 assert(lnzeros != NULL);
3804 assert(lintnzeros != NULL);
3805 assert(nonzeros != NULL);
3806 assert(intnzeros != NULL);
3807
3808 for( b = 0; b < GCGdecompGetNBlocks(decomp); ++b )
3809 {
3810 SCIP_CONS** subscipconss = GCGdecompGetSubscipconss(decomp)[b];
3811 int nsubscipconss = GCGdecompGetNSubscipconss(decomp)[b];
3812 for( c = 0; c < nsubscipconss; ++c )
3813 {
3814 SCIP_CALL( computeConssNzeros(gcg, decomp, subscipconss[c], &(nonzeros[b]), &(intnzeros[b]), lnzeros, lintnzeros ) );
3815 }
3816 }
3817
3818 for( c = 0; c < GCGdecompGetNLinkingconss(decomp); ++c )
3819 {
3820 SCIP_CALL( computeConssNzeros(gcg, decomp, GCGdecompGetLinkingconss(decomp)[c], mnzeros, mintnzeros, lnzeros, lintnzeros ) );
3821 }
3822
3823 return SCIP_OKAY;
3824}
3825
3826/** display statistics about the decomposition */
3828 GCG* gcg, /**< GCG data structure */
3829 FILE* file, /**< output file or NULL for standard output */
3830 GCG_DECOMP* decomp /**< decomp that should be evaluated */
3831 )
3832{
3833 DEC_SCORES scores;
3834 SCIP_VAR** vars;
3835 SCIP_CONS** conss;
3836 SCIP* origprob;
3837
3838 int nvars;
3839 int nconss;
3840
3841 int* nallvars;
3842 int* nbinvars;
3843 int* nintvars;
3844 int* nimplvars;
3845 int* ncontvars;
3846
3847 int nblocks;
3848 int nblocksrelevant;
3849 int nlinkvars;
3850 int nstaticvars;
3851 int nlinkbinvar;
3852 int nlinkintvars;
3853 int nlinkimplvars;
3854 int nlinkcontvars;
3855 int b;
3856
3857 int* varprobdensity;
3858 int* varmasterdensity;
3859 int* consprobsensity;
3860 int* consmasterdensity;
3861
3862 DEC_STATISTIC* blockvardensities;
3863 DEC_STATISTIC* blockconsdensities;
3864 DEC_STATISTIC mastervardensity;
3865
3866 int mnzeros;
3867 int mintnzeros;
3868 int lnzeros;
3869 int lintnzeros;
3870
3871 int* nonzeros;
3872 int* intnzeros;
3873
3874 origprob = GCGgetOrigprob(gcg);
3875 assert(origprob != NULL);
3876 assert(decomp != NULL);
3877
3878 nblocks = GCGdecompGetNBlocks(decomp);
3879 nvars = SCIPgetNVars(origprob);
3880 nconss = GCGdecompGetNConss(decomp);
3881
3882 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &nallvars, nblocks) );
3883 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &nbinvars, nblocks) );
3884 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &nintvars, nblocks) );
3885 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &nimplvars, nblocks) );
3886 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &ncontvars, nblocks) );
3887
3888 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &blockvardensities, nblocks) );
3889 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &blockconsdensities, nblocks) );
3890
3891 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &varprobdensity, nvars) );
3892 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &varmasterdensity, nvars) );
3893 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &vars, nvars) );
3894 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &conss, nconss) );
3895 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &consprobsensity, nconss) );
3896 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &consmasterdensity, nconss) );
3897
3898 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &nonzeros, nblocks) );
3899 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &intnzeros, nblocks) );
3900
3901 BMSclearMemoryArray(nonzeros, nblocks);
3902 BMSclearMemoryArray(intnzeros, nblocks);
3903
3904 mnzeros = 0;
3905 mintnzeros = 0;
3906 lnzeros = 0;
3907 lintnzeros = 0;
3908
3909 SCIP_CALL( GCGdecompEvaluateDecomposition(gcg, decomp, &scores) );
3910
3911 GCGgetSubproblemVarsData(gcg, decomp, nallvars, nbinvars, nintvars, nimplvars, ncontvars, nblocks);
3912 GCGgetLinkingVarsData(gcg, decomp, &nlinkvars, &nlinkbinvar, &nlinkintvars, &nlinkimplvars, &nlinkcontvars);
3913 nlinkvars = nlinkvars - GCGdecompGetNMastervars(decomp);
3914 nstaticvars = GCGdecompGetNMastervars(decomp);
3915
3916 SCIP_CALL( GCGgetDensityData(gcg, decomp, vars, nvars, conss, nconss, varprobdensity, varmasterdensity, consprobsensity, consmasterdensity) );
3917
3918 SCIP_CALL( computeVarDensities(gcg, decomp, varprobdensity, varmasterdensity, vars, nvars, blockvardensities, &mastervardensity, nblocks) );
3919 SCIP_CALL( computeNonzeros(gcg, decomp, &mnzeros, &mintnzeros, &lnzeros, &lintnzeros, nonzeros, intnzeros) );
3920
3921 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "Decomp statistics :\n");
3922 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " type : %10s\n", GCGdecompGetStrType(GCGdecompGetType(decomp)));
3923 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " detector : %10s\n", decomp->detectorchainstring == NULL? "provided": decomp->detectorchainstring);
3924 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " blocks : %10d\n", GCGdecompGetNBlocks(decomp));
3925
3926 nblocksrelevant = nblocks;
3928 {
3929 for( b = 0; b < nblocks; ++b )
3930 {
3931 if( GCGgetNIdenticalBlocks(gcg, b) == 0 )
3932 nblocksrelevant -= 1;
3933 }
3934 }
3935 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " aggr. blocks : %10d\n", nblocksrelevant);
3936
3937 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "Master statistics : nlinkvars nstatvars nbinvars nintvars nimplvars ncontvars nconss nonzeros intnzeros bnzeros bintnzeros min(dens) max(dens) medi(dens) mean(dens)\n");
3938 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " master : %10d %10d %9d %9d %9d %10d %8d %9d %9d %9d %10d %9.3f %9.3f %10.3f %9.3f\n", nlinkvars, nstaticvars,
3939 nlinkbinvar, nlinkintvars, nlinkimplvars, nlinkcontvars, GCGdecompGetNLinkingconss(decomp),
3940 mnzeros, mintnzeros, lnzeros, lintnzeros, mastervardensity.min, mastervardensity.max, mastervardensity.median, mastervardensity.mean);
3941
3942 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "Pricing statistics : nvars nbinvars nintvars nimplvars ncontvars nconss nonzeros intnzeros min(dens) max(dens) medi(dens) mean(dens) identical\n");
3943 for( b = 0; b < nblocks; ++b )
3944 {
3945 int identical = 0;
3946 SCIP_Bool relevant = TRUE;
3947
3949 {
3950 relevant = GCGisPricingprobRelevant(gcg, b);
3951 identical = GCGgetNIdenticalBlocks(gcg, b);
3952 }
3953 if( relevant )
3954 {
3955 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " %10d : %10d %10d %10d %10d %10d %10d %10d %10d %10.3f %10.3f %10.3f %10.3f %10d\n", b+1, nallvars[b], nbinvars[b], nintvars[b], nimplvars[b], ncontvars[b],
3956 GCGdecompGetNSubscipconss(decomp)[b], nonzeros[b], intnzeros[b], blockvardensities[b].min, blockvardensities[b].max, blockvardensities[b].median, blockvardensities[b].mean, identical);
3957 }
3958 }
3959
3960 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "Decomp Scores :\n");
3961 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " border area : %10.3f\n", scores.borderscore);
3962 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " avg. density : %10.3f\n", scores.densityscore);
3963 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, " linking score : %10.3f\n", scores.linkingscore);
3964
3965 SCIPfreeBlockMemoryArray(origprob, &vars, nvars);
3966 SCIPfreeBlockMemoryArray(origprob, &conss, nconss);
3967
3968
3969 SCIPfreeBlockMemoryArray(origprob, &intnzeros, nblocks);
3970 SCIPfreeBlockMemoryArray(origprob, &nonzeros, nblocks);
3971
3972 SCIPfreeBlockMemoryArray(origprob, &varprobdensity, nvars);
3973 SCIPfreeBlockMemoryArray(origprob, &varmasterdensity, nvars);
3974 SCIPfreeBlockMemoryArray(origprob, &consprobsensity, nconss);
3975 SCIPfreeBlockMemoryArray(origprob, &consmasterdensity, nconss);
3976
3977 SCIPfreeBlockMemoryArray(origprob, &blockvardensities, nblocks);
3978 SCIPfreeBlockMemoryArray(origprob, &blockconsdensities, nblocks);
3979
3980 SCIPfreeBlockMemoryArray(origprob, &nallvars, nblocks);
3981 SCIPfreeBlockMemoryArray(origprob, &nbinvars, nblocks);
3982 SCIPfreeBlockMemoryArray(origprob, &nintvars, nblocks);
3983 SCIPfreeBlockMemoryArray(origprob, &nimplvars, nblocks);
3984 SCIPfreeBlockMemoryArray(origprob, &ncontvars, nblocks);
3985
3986 return SCIP_OKAY;
3987}
3988
3989/** returns whether both structures lead to the same decomposition */
3991 GCG* gcg, /**< GCG data structure */
3992 GCG_DECOMP* decomp1, /**< first decomp data structure */
3993 GCG_DECOMP* decomp2 /**< second decomp data structure */
3994)
3995{
3996 SCIP* scip;
3997 SCIP_HASHMAP* constoblock1;
3998 SCIP_HASHMAP* constoblock2;
3999
4000 SCIP_HASHMAP* vartoblock1;
4001 SCIP_HASHMAP* vartoblock2;
4002
4003 SCIP_CONS** conss;
4004 int nconss;
4005
4006 SCIP_VAR** vars;
4007 int nvars;
4008 int i;
4009
4010 assert(gcg != NULL);
4011 assert(decomp1 != NULL);
4012 assert(decomp2 != NULL);
4013
4015 if( GCGdecompGetNBlocks(decomp1) != GCGdecompGetNBlocks(decomp2) )
4016 {
4017 return FALSE;
4018 }
4019
4020 conss = SCIPgetConss(scip);
4021 nconss = SCIPgetNConss(scip);
4022
4023 vars = SCIPgetVars(scip);
4024 nvars = SCIPgetNVars(scip);
4025
4026 constoblock1 = GCGdecompGetConstoblock(decomp1);
4027 constoblock2 = GCGdecompGetConstoblock(decomp2);
4028 assert(constoblock1 != NULL);
4029 assert(constoblock2 != NULL);
4030
4031 vartoblock1 = GCGdecompGetVartoblock(decomp1);
4032 vartoblock2 = GCGdecompGetVartoblock(decomp2);
4033 assert(vartoblock1 != NULL);
4034 assert(vartoblock2 != NULL);
4035
4036 vartoblock1 = GCGdecompGetVartoblock(decomp1);
4037 vartoblock2 = GCGdecompGetVartoblock(decomp2);
4038
4039 for( i = 0; i < nconss; ++i )
4040 {
4041 if( SCIPhashmapGetImage(constoblock1, conss[i]) != SCIPhashmapGetImage(constoblock2, conss[i]) )
4042 return FALSE;
4043 }
4044
4045 for( i = 0; i < nvars; ++i )
4046 {
4047 if( SCIPhashmapGetImage(vartoblock1, vars[i]) != SCIPhashmapGetImage(vartoblock2, vars[i]) )
4048 return FALSE;
4049 }
4050
4051 return TRUE;
4052}
4053
4054/** filters similar decompositions from a given list and moves them to the end
4055 * @return the number of unique decompositions
4056 */
4058 GCG* gcg, /**< GCG data structure */
4059 GCG_DECOMP** decs, /**< array of decompositions */
4060 int ndecs /**< number of decompositions */
4061)
4062{
4063 int i;
4064 int j;
4065 int nunique;
4066 assert(gcg != NULL);
4067 assert(decs != NULL);
4068 assert(ndecs > 0);
4069
4070 nunique = ndecs;
4071 for( i = 0; i < nunique; ++i )
4072 {
4073 /*lint -e{850} j is modified in the body of the for loop */
4074 for( j = i+1; j < nunique; ++j )
4075 {
4076 GCG_DECOMP* tmp;
4077 if( GCGdecompositionsAreEqual(gcg, decs[i], decs[j]) )
4078 {
4079 tmp = decs[nunique-1];
4080 decs[nunique-1] = decs[j];
4081 decs[j] = tmp;
4082 --nunique;
4083 --j;
4084 }
4085 }
4086 }
4087 return nunique;
4088}
4089
4090/** returns the number of the block that the constraint is with respect to the decomposition; set
4091 * *block = -2, if it has no variables
4092 * *block = -1, if it has only variables belonging only to the master (meaning that this constraint should build a new block)
4093 * *block in [0,...,nblocks-1] if it only contains variables of a particular block (plus linking variables)
4094 * *block = nblocks, if it contains
4095 * - either variables from more than one block (plus linking variables or master only variables)
4096 * - or linking variables only
4097 */
4098/** @todo: For linking variables, we should check which blocks they actually link */
4099/** @todo: maybe this is possible in such a way that a staircase structure is preserved */
4101 GCG* gcg, /**< GCG data structure */
4102 GCG_DECOMP* decomp, /**< decomposition data structure */
4103 SCIP_CONS* cons, /**< constraint to check */
4104 int* block /**< block of the constraint (or nblocks for master) */
4105)
4106{
4107 SCIP* scip;
4108 SCIP_VAR** curvars = NULL;
4109 int ncurvars = 0;
4110 SCIP_Bool success = FALSE;
4111 int i;
4112 int nblocks ;
4113
4114 int nmastervars = 0;
4115 int npricingvars = 0;
4116
4117 SCIP_HASHMAP* vartoblock;
4118 assert(gcg != NULL);
4119 assert(decomp != NULL);
4120 assert(cons != NULL);
4121 assert(block != NULL);
4122
4123 *block = -2;
4124
4126 SCIP_CALL( SCIPgetConsNVars(scip, cons, &ncurvars, &success) );
4127 assert(success);
4128
4129 if( ncurvars == 0 )
4130 return SCIP_OKAY;
4131
4132 vartoblock= GCGdecompGetVartoblock(decomp);
4133 assert(vartoblock != NULL);
4134
4135 nblocks = GCGdecompGetNBlocks(decomp);
4136
4137 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
4138 SCIP_CALL( SCIPgetConsVars(scip, cons, curvars, ncurvars, &success) );
4139 assert(success);
4140
4141 for( i = 0; i < ncurvars && *block != nblocks; ++i )
4142 {
4143 SCIP_VAR* var;
4144 int varblock;
4145
4146 var = SCIPvarGetProbvar(curvars[i]);
4147
4149 continue;
4150
4151 assert(SCIPhashmapExists(vartoblock, var));
4152 varblock = ((int) (size_t) SCIPhashmapGetImage(vartoblock, var))-1; /*lint !e507 */
4153
4154 /* if variable is linking skip*/
4155 if( varblock == nblocks+1 )
4156 {
4157 continue;
4158 }
4159 else if( varblock == nblocks )
4160 {
4161 ++nmastervars;
4162 continue;
4163 }
4164 else if( *block != varblock )
4165 {
4166 ++npricingvars;
4167 if( *block < 0 )
4168 *block = varblock;
4169 else
4170 {
4171 assert(*block != nblocks);
4172 *block = nblocks;
4173 break;
4174 }
4175 }
4176 }
4177
4178 SCIPfreeBufferArrayNull(scip, &curvars);
4179
4180 if( ncurvars > 0 && *block == -2 )
4181 *block = nblocks;
4182
4183 if( npricingvars == 0 && nmastervars > 0 )
4184 *block = -1;
4185
4186
4187
4188 return SCIP_OKAY;
4189}
4190
4191/** move a master constraint to pricing problem */
4193 GCG* gcg, /**< GCG data structure */
4194 GCG_DECOMP* decomp, /**< decomposition data structure */
4195 int consindex, /**< index of constraint to move */
4196 int block /**< block of the pricing problem where to move */
4197 )
4198{
4199 SCIP* scip;
4200 SCIP_CONS* linkcons;
4201 int oldsize;
4202 int newsize;
4203
4204 assert(gcg != NULL);
4205 assert(decomp != NULL);
4206 assert(consindex >= 0 && consindex < decomp->nlinkingconss);
4207 assert(block >= 0 && block < decomp->nblocks);
4208
4210 linkcons = decomp->linkingconss[consindex];
4211
4212 decomp->linkingconss[consindex] = decomp->linkingconss[decomp->nlinkingconss-1];
4213 decomp->nlinkingconss -= 1;
4214
4215 oldsize = SCIPcalcMemGrowSize(scip, decomp->nsubscipconss[block]);
4216 newsize = SCIPcalcMemGrowSize(scip, decomp->nsubscipconss[block]+1);
4217 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &decomp->subscipconss[block], oldsize, newsize) ); /*lint !e866 */
4218 decomp->subscipconss[block][decomp->nsubscipconss[block]] = linkcons;
4219 decomp->nsubscipconss[block] += 1;
4220
4221 SCIP_CALL( SCIPhashmapSetImage(decomp->constoblock, linkcons, (void*) (size_t)((size_t)block+1)) );
4222 SCIP_CALL( assignConsvarsToBlock(gcg, decomp, linkcons, block) );
4223
4224 return SCIP_OKAY;
4225}
4226
4227
4228/** tries to assign masterconss to pricing problem */
4230 GCG* gcg, /**< GCG data structure */
4231 GCG_DECOMP* decomp, /**< decomposition data structure */
4232 int* transferred /**< number of master constraints reassigned */
4233 )
4234{
4235 SCIP* scip;
4236 int c;
4237 int linkingconssize;
4238 assert(gcg != NULL);
4239 assert(decomp != NULL);
4240 assert(transferred != NULL);
4242 linkingconssize = decomp->nlinkingconss;
4243 *transferred = 0;
4244
4245 /*lint -e{850} c is modified in the body of the for loop */
4246 for( c = 0; c < decomp->nlinkingconss; ++c )
4247 {
4248 int block;
4249 SCIP_CALL( GCGdetermineConsBlock(gcg, decomp, decomp->linkingconss[c], &block) );
4250
4251 if( block == GCGdecompGetNBlocks(decomp) || block < 0 )
4252 {
4253 continue;
4254 }
4255
4256 SCIP_CALL( GCGdecompMoveLinkingConsToPricing(gcg, decomp, c, block) );
4257 --c;
4258 *transferred += 1;
4259 }
4260
4261 if( *transferred > 0 )
4262 {
4263 if( decomp->nlinkingconss > 0 )
4264 {
4265 int oldsize = SCIPcalcMemGrowSize(scip, linkingconssize);
4266 int newsize = SCIPcalcMemGrowSize(scip, decomp->nlinkingconss);
4267 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &decomp->linkingconss, oldsize, newsize) );
4268 }
4269 else
4270 {
4272 }
4273 }
4274
4275 return SCIP_OKAY;
4276}
4277
4278/** tries to assign masterconss to new pricing problem */
4280 GCG* gcg, /**< GCG data structure */
4281 GCG_DECOMP* decomp, /**< decomposition data structure */
4282 GCG_DECOMP** newdecomp, /**< new decomposition, if successful */
4283 int* transferred /**< number of master constraints reassigned */
4284 )
4285{
4286 SCIP* scip;
4287 int c;
4288
4289 assert(gcg != NULL);
4290 assert(decomp != NULL);
4291 assert(newdecomp != NULL);
4292 assert(transferred != NULL);
4293
4295 *newdecomp = NULL;
4296 *transferred = 0;
4297
4298 for( c = 0; c < decomp->nlinkingconss; ++c )
4299 {
4300 int block;
4301 int i;
4302 int nconss;
4303 SCIP_HASHMAP* constoblock;
4304 SCIP_CALL( GCGdetermineConsBlock(gcg, decomp, decomp->linkingconss[c], &block) );
4305
4306 if( block >= 0 )
4307 {
4308 continue;
4309 }
4310 SCIPdebugMessage("Cons <%s> in new pricing problem\n", SCIPconsGetName(decomp->linkingconss[c]));
4311 nconss = SCIPgetNConss(scip);
4312 SCIP_CALL( GCGdecompCreate(gcg, newdecomp) );
4314
4315 for( i = 0; i < nconss; ++i )
4316 {
4317 int consblock;
4318 SCIP_CONS* cons = SCIPgetConss(scip)[i];
4319 assert(SCIPhashmapExists(decomp->constoblock, cons));
4320 consblock = (int) (size_t) SCIPhashmapGetImage(decomp->constoblock, cons); /*lint !e507 */
4321 SCIPdebugMessage("Cons <%s> %d -> %d\n", SCIPconsGetName(cons), consblock, consblock+1);
4322
4323 SCIP_CALL( SCIPhashmapSetImage(constoblock, cons, (void*) (size_t) (consblock+1)) );
4324 }
4325 SCIP_CALL( SCIPhashmapSetImage(constoblock, decomp->linkingconss[c], (void*) (size_t) (1)) );
4326 SCIPdebugMessage("Cons <%s> -> %d\n", SCIPconsGetName(decomp->linkingconss[c]), 1);
4327
4328 SCIP_CALL( GCGfilloutDecompFromConstoblock(gcg, *newdecomp, constoblock, decomp->nblocks+1, FALSE) );
4329 *transferred += 1;
4330 break;
4331 }
4332
4333 return SCIP_OKAY;
4334}
4335
4336/** polish the decomposition and try to greedily assign master constraints to pricing problem where useful */
4338 GCG* gcg, /**< GCG data structure */
4339 GCG_DECOMP* decomp, /**< decomposition data structure */
4340 GCG_DECOMP** newdecomp /**< new decomposition, if successful */
4341 )
4342{
4343 int transferredexisting = 0;
4344 int transferrednew = 0;
4345 GCG_DECOMP* origdecomp = decomp;
4346 GCG_DECOMP* tempdecomp = NULL;
4347
4348 assert(gcg != NULL);
4349 assert(decomp != NULL);
4350 assert(newdecomp != NULL);
4351
4352 if( GCGdecompGetNBlocks(decomp) == 1 )
4353 {
4354 *newdecomp = NULL;
4355 return SCIP_OKAY;
4356 }
4357 *newdecomp = decomp;
4358
4359 do
4360 {
4361 SCIP_CALL( GCGdecompTryAssignMasterconssToExistingPricing(gcg, *newdecomp, &transferredexisting) );
4362 SCIPdebugMessage("%d conss transferred to existing pricing\n", transferredexisting);
4363 SCIP_CALL( GCGdecompTryAssignMasterconssToNewPricing(gcg, *newdecomp, &tempdecomp, &transferrednew) );
4364 SCIPdebugMessage("%d conss transferred to new pricing\n", transferrednew);
4365 if( transferrednew > 0 )
4366 {
4367 if( *newdecomp != origdecomp )
4368 {
4369 SCIP_CALL( GCGdecompFree(gcg, newdecomp) );
4370 }
4371 *newdecomp = tempdecomp;
4372 }
4373 } while( transferredexisting > 0 || transferrednew > 0 );
4374
4375 if( *newdecomp == origdecomp )
4376 {
4377 *newdecomp = NULL;
4378 }
4379
4380 return SCIP_OKAY;
4381}
4382
4383/** permutes the decomposition according to the permutation seed */
4385 GCG* gcg, /**< GCG data structure */
4386 GCG_DECOMP* decomp, /**< decomposition data structure */
4387 SCIP_RANDNUMGEN* randnumgen /**< random number generator */
4388 )
4389{
4390 int b;
4391 int npricingprobs;
4392 assert(gcg != NULL);
4393 assert(decomp != NULL);
4394
4395 npricingprobs = GCGdecompGetNBlocks(decomp);
4396
4397 /* Permute individual variables and constraints of pricing problems */
4398 for( b = 0; b < npricingprobs; ++b )
4399 {
4400 SCIP_CONS*** subscipconss;
4401 SCIP_VAR*** subscipvars;
4402 int *nsubscipconss = GCGdecompGetNSubscipconss(decomp);
4403 int *nsubscipvars = GCGdecompGetNSubscipvars(decomp);
4404 subscipconss = GCGdecompGetSubscipconss(decomp);
4405
4406 SCIPrandomPermuteArray(randnumgen, (void**)(subscipconss[b]), 0, nsubscipconss[b]);
4407
4408 subscipvars = GCGdecompGetSubscipvars(decomp);
4409 SCIPrandomPermuteArray(randnumgen, (void**)(subscipvars[b]), 0, nsubscipvars[b]);
4410 }
4411
4412 if( GCGdecompGetNLinkingconss(decomp) > 0 )
4413 {
4414 SCIP_CONS** linkingconss = GCGdecompGetLinkingconss(decomp);
4415 SCIPrandomPermuteArray(randnumgen, (void**)linkingconss, 0, GCGdecompGetNLinkingconss(decomp));
4416 }
4417
4418 if( GCGdecompGetNLinkingvars(decomp) > 0 )
4419 {
4420 SCIP_VAR** linkingvars = GCGdecompGetLinkingvars(decomp);;
4421 SCIPrandomPermuteArray(randnumgen, (void**)linkingvars, 0, GCGdecompGetNLinkingvars(decomp));
4422 }
4423
4425 return SCIP_OKAY;
4426}
SCIP_VAR ** b
int GCGconshdlrDecompDecreaseNCallsCreateDecomp(GCG *gcg)
decreases the counter for created decompositions and returns it
int GCGconshdlrDecompIncreaseNCallsCreateDecomp(GCG *gcg)
counts up the counter for created decompositions and returns it
constraint handler for structure detection
GCG_EXPORT SCIP_RETCODE GCGdecompSetDetectorChainString(GCG *gcg, GCG_DECOMP *decomp, const char *detectorchainstring)
Definition: decomp.c:1730
void GCGdecompSetConsindex(GCG_DECOMP *decomp, SCIP_HASHMAP *consindex)
Definition: decomp.c:1273
SCIP_Real * GCGdecompGetDetectorClockTimes(GCG_DECOMP *decomp)
Definition: decomp.c:1721
SCIP_RETCODE GCGdetermineConsBlock(GCG *gcg, GCG_DECOMP *decomp, SCIP_CONS *cons, int *block)
Definition: decomp.c:4100
GCG_EXPORT SCIP_Real * GCGdecompGetDetectorPctConssToBlock(GCG_DECOMP *decomp)
Definition: decomp.c:1886
void GCGdecompSetPresolved(GCG_DECOMP *decomp, SCIP_Bool presolved)
Definition: decomp.c:724
void GCGdecompSetMaxWhiteScore(GCG *gcg, GCG_DECOMP *decdecomp, SCIP_Real maxwhitescore)
Definition: decomp.c:3296
GCG_DETECTOR ** GCGdecompGetDetectorChain(GCG_DECOMP *decomp)
Definition: decomp.c:1626
SCIP_Bool GCGdecompGetPresolved(GCG_DECOMP *decomp)
Definition: decomp.c:735
void GCGdecompSetDetector(GCG_DECOMP *decomp, GCG_DETECTOR *detector)
Definition: decomp.c:1605
SCIP_VAR *** GCGdecompGetStairlinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1173
SCIP_VAR ** GCGdecompGetLinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1056
static SCIP_RETCODE computeConssNzeros(GCG *gcg, GCG_DECOMP *decomp, SCIP_CONS *cons, int *nzeros, int *nintzeros, int *nbzeros, int *nintbzeros)
Definition: decomp.c:3714
SCIP_RETCODE GCGcreateBasicDecomp(GCG *gcg, GCG_DECOMP **decomp, SCIP_Bool solveorigprob)
Definition: decomp.c:2418
SCIP_RETCODE GCGdecompCheckConsistency(GCG *gcg, GCG_DECOMP *decdecomp)
Definition: decomp.c:2297
SCIP_RETCODE GCGcreateDecompFromMasterconss(GCG *gcg, GCG_DECOMP **decomp, SCIP_CONS **masterconss, int nmasterconss)
Definition: decomp.c:2748
int GCGdecompGetPartialdecID(GCG_DECOMP *decomp)
Definition: decomp.c:1685
void GCGdecompSetVarindex(GCG_DECOMP *decomp, SCIP_HASHMAP *varindex)
Definition: decomp.c:1253
static SCIP_RETCODE fillOutConsFromConstoblock(GCG *gcg, GCG_DECOMP *decomp, SCIP_HASHMAP *constoblock, int nblocks, SCIP_CONS **conss, int nconss, SCIP_Bool *haslinking)
Definition: decomp.c:245
SCIP_CONS *** GCGdecompGetSubscipconss(GCG_DECOMP *decomp)
Definition: decomp.c:924
SCIP_HASHMAP * GCGdecompGetConstoblock(GCG_DECOMP *decomp)
Definition: decomp.c:1243
SCIP_RETCODE GCGprintDecompStatistics(GCG *gcg, FILE *file, GCG_DECOMP *decomp)
Definition: decomp.c:3827
SCIP_Real * GCGdecompGetDetectorPctConssToBorder(GCG_DECOMP *decomp)
Definition: decomp.c:1816
int GCGdecompGetNLinkingconss(GCG_DECOMP *decomp)
Definition: decomp.c:995
static void increaseLock(GCG *gcg, SCIP_Real lhs, SCIP_Real coef, SCIP_Real rhs, int *downlock, int *uplock)
Definition: decomp.c:3118
SCIP_Bool GCGdecompositionsAreEqual(GCG *gcg, GCG_DECOMP *decomp1, GCG_DECOMP *decomp2)
Definition: decomp.c:3990
SCIP_RETCODE GCGdecompSetType(GCG_DECOMP *decomp, GCG_DECTYPE type)
Definition: decomp.c:659
SCIP_RETCODE GCGdecompAddRemainingConss(GCG *gcg, GCG_DECOMP *decdecomp)
Definition: decomp.c:2206
SCIP_RETCODE GCGfilloutDecompFromConstoblock(GCG *gcg, GCG_DECOMP *decomp, SCIP_HASHMAP *constoblock, int nblocks, SCIP_Bool staircase)
Definition: decomp.c:1479
SCIP_RETCODE GCGdecompTryAssignMasterconssToNewPricing(GCG *gcg, GCG_DECOMP *decomp, GCG_DECOMP **newdecomp, int *transferred)
Definition: decomp.c:4279
SCIP_RETCODE GCGdecompCreate(GCG *gcg, GCG_DECOMP **decdecomp)
Definition: decomp.c:480
SCIP_RETCODE GCGdecompSetSubscipvars(GCG *gcg, GCG_DECOMP *decomp, SCIP_VAR ***subscipvars, int *nsubscipvars)
Definition: decomp.c:767
SCIP_Real * GCGdecompGetDetectorPctVarsFromOpen(GCG_DECOMP *decomp)
Definition: decomp.c:1924
SCIP_RETCODE GCGdecompRemoveDeletedConss(GCG *gcg, GCG_DECOMP *decdecomp)
Definition: decomp.c:2148
SCIP_RETCODE GCGcreatePolishedDecomp(GCG *gcg, GCG_DECOMP *decomp, GCG_DECOMP **newdecomp)
Definition: decomp.c:4337
int * GCGdecompGetNNewBlocks(GCG_DECOMP *decomp)
Definition: decomp.c:1997
SCIP_RETCODE GCGfilloutDecompFromHashmaps(GCG *gcg, GCG_DECOMP *decomp, SCIP_HASHMAP *vartoblock, SCIP_HASHMAP *constoblock, int nblocks, SCIP_Bool staircase)
Definition: decomp.c:1293
SCIP_CONS ** GCGdecompGetLinkingconss(GCG_DECOMP *decomp)
Definition: decomp.c:985
void GCGdecompSetNNewBlocks(GCG *gcg, GCG_DECOMP *decomp, int *nNewBlocks)
Definition: decomp.c:1970
int GCGdecompGetNMastervars(GCG_DECOMP *decomp)
Definition: decomp.c:1089
void GCGgetLinkingVarsData(GCG *gcg, GCG_DECOMP *decomp, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: decomp.c:2922
static SCIP_RETCODE computeVarDensities(GCG *gcg, GCG_DECOMP *decomp, int *varprobdensity, int *varmasterdensity, SCIP_VAR **vars, int nvars, DEC_STATISTIC *blockvardensities, DEC_STATISTIC *mastervardensity, int nblocks)
Definition: decomp.c:3557
SCIP_RETCODE GCGdecompTryAssignMasterconssToExistingPricing(GCG *gcg, GCG_DECOMP *decomp, int *transferred)
Definition: decomp.c:4229
GCG_EXPORT char * GCGdecompGetDetectorChainString(GCG *gcg, GCG_DECOMP *decomp)
Definition: decomp.c:1745
GCG_DETECTOR * GCGdecompGetDetector(GCG_DECOMP *decomp)
Definition: decomp.c:1616
static SCIP_RETCODE computeNonzeros(GCG *gcg, GCG_DECOMP *decomp, int *mnzeros, int *mintnzeros, int *lnzeros, int *lintnzeros, int *nonzeros, int *intnzeros)
Definition: decomp.c:3785
SCIP_RETCODE GCGdecompSetLinkingvars(GCG *gcg, GCG_DECOMP *decomp, SCIP_VAR **linkingvars, int nlinkingvars, int nfixedlinkingvars, int nmastervars)
Definition: decomp.c:1007
int GCGdecompGetNTotalStairlinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1192
void GCGdecompSetVartoblock(GCG_DECOMP *decomp, SCIP_HASHMAP *vartoblock)
Definition: decomp.c:1209
void GCGdecompSetPartialdecID(GCG_DECOMP *decomp, int id)
Definition: decomp.c:1673
SCIP_RETCODE GCGdecompSetStairlinkingvars(GCG *gcg, GCG_DECOMP *decomp, SCIP_VAR ***stairlinkingvars, int *nstairlinkingvars)
Definition: decomp.c:1101
void GCGdecompSetDetectorPctVarsToBorder(GCG *gcg, GCG_DECOMP *decomp, SCIP_Real *pctVarsToBorder)
Definition: decomp.c:1754
#define ELEM_SWAP(a, b)
Definition: decomp.c:60
SCIP_HASHMAP * GCGdecompGetVartoblock(GCG_DECOMP *decomp)
Definition: decomp.c:1221
SCIP_HASHMAP * GCGdecompGetConsindex(GCG_DECOMP *decomp)
Definition: decomp.c:1284
void GCGdecompSetNBlocks(GCG_DECOMP *decomp, int nblocks)
Definition: decomp.c:745
void GCGdecompSetDetectorPctConssFromOpen(GCG *gcg, GCG_DECOMP *decomp, SCIP_Real *pctConssFromOpen)
Definition: decomp.c:1932
static SCIP_RETCODE fillConstoblock(SCIP_CONS **conss, int nconss, SCIP_Bool *consismaster, int nblocks, SCIP_HASHMAP *constoblock, SCIP_HASHMAP *newconstoblock, int *blockrepresentative)
Definition: decomp.c:2703
static SCIP_RETCODE assignConsvarsToBlock(GCG *gcg, GCG_DECOMP *decomp, SCIP_CONS *cons, int block)
Definition: decomp.c:417
SCIP_RETCODE GCGdecompSetSubscipconss(GCG *gcg, GCG_DECOMP *decomp, SCIP_CONS ***subscipconss, int *nsubscipconss)
Definition: decomp.c:857
int GCGdecompGetNConss(GCG_DECOMP *decomp)
Definition: decomp.c:3697
SCIP_RETCODE GCGdecompSetLinkingconss(GCG *gcg, GCG_DECOMP *decomp, SCIP_CONS **linkingconss, int nlinkingconss)
Definition: decomp.c:942
int * GCGdecompGetNSubscipvars(GCG_DECOMP *decomp)
Definition: decomp.c:847
void GCGdecompSetDetectorPctVarsFromOpen(GCG *gcg, GCG_DECOMP *decomp, SCIP_Real *pctVarsFromOpen)
Definition: decomp.c:1895
void GCGdecompSetDetectorPctVarsToBlock(GCG *gcg, GCG_DECOMP *decomp, SCIP_Real *pctVarsToBlock)
Definition: decomp.c:1824
SCIP_Real GCGdecompGetMaxwhiteScore(GCG_DECOMP *decomp)
Definition: decomp.c:713
static int processBlockRepresentatives(int maxblock, int *blockrepresentative)
Definition: decomp.c:2485
SCIP_RETCODE GCGdecompEvaluateDecomposition(GCG *gcg, GCG_DECOMP *decdecomp, DEC_SCORES *score)
Definition: decomp.c:3331
void GCGdecompSetDetectorClockTimes(GCG *gcg, GCG_DECOMP *decomp, SCIP_Real *detectorClockTimes)
Definition: decomp.c:1694
SCIP_RETCODE GCGdecompFree(GCG *gcg, GCG_DECOMP **decdecomp)
Definition: decomp.c:541
int GCGdecompGetNBlocks(GCG_DECOMP *decomp)
Definition: decomp.c:757
SCIP_Real * GCGdecompGetDetectorPctVarsToBlock(GCG_DECOMP *decomp)
Definition: decomp.c:1850
static SCIP_Real quick_select_median(SCIP_Real arr[], int n)
Definition: decomp.c:63
static SCIP_RETCODE fillOutVarsFromVartoblock(GCG *gcg, GCG_DECOMP *decomp, SCIP_HASHMAP *vartoblock, int nblocks, SCIP_VAR **vars, int nvars, SCIP_Bool *haslinking)
Definition: decomp.c:124
int GCGdecompGetNLinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1066
SCIP_VAR *** GCGdecompGetSubscipvars(GCG_DECOMP *decomp)
Definition: decomp.c:837
SCIP_HASHMAP * GCGdecompGetVarindex(GCG_DECOMP *decomp)
Definition: decomp.c:1264
void GCGdecompSetDetectorPctConssToBlock(GCG *gcg, GCG_DECOMP *decomp, SCIP_Real *pctConssToBlock)
Definition: decomp.c:1858
void GCGdecompSetDetectorPctConssToBorder(GCG *gcg, GCG_DECOMP *decomp, SCIP_Real *pctConssToBorder)
Definition: decomp.c:1788
GCG_DECTYPE GCGdecompGetType(GCG_DECOMP *decomp)
Definition: decomp.c:703
SCIP_RETCODE GCGpermuteDecomp(GCG *gcg, GCG_DECOMP *decomp, SCIP_RANDNUMGEN *randnumgen)
Definition: decomp.c:4384
SCIP_Real * GCGdecompGetDetectorPctConssFromOpen(GCG_DECOMP *decomp)
Definition: decomp.c:1962
int GCGfilterSimilarDecompositions(GCG *gcg, GCG_DECOMP **decs, int ndecs)
Definition: decomp.c:4057
int * GCGdecompGetNSubscipconss(GCG_DECOMP *decomp)
Definition: decomp.c:933
int GCGdecompGetNFixedLinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1077
SCIP_RETCODE GCGgetDensityData(GCG *gcg, GCG_DECOMP *decomp, SCIP_VAR **vars, int nvars, SCIP_CONS **conss, int nconss, int *varsubproblemdensity, int *varmasterdensity, int *conssubproblemdensity, int *consmasterdensity)
Definition: decomp.c:2972
const char * GCGdecompGetStrType(GCG_DECTYPE type)
Definition: decomp.c:471
void GCGgetSubproblemVarsData(GCG *gcg, GCG_DECOMP *decomp, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars, int nproblems)
Definition: decomp.c:2873
SCIP_RETCODE GCGdecompMoveLinkingConsToPricing(GCG *gcg, GCG_DECOMP *decomp, int consindex, int block)
Definition: decomp.c:4192
int * GCGdecompGetNStairlinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1182
static SCIP_RETCODE removeFromLinkingvars(GCG *gcg, GCG_DECOMP *decomp, SCIP_VAR *var, SCIP_Bool *success)
Definition: decomp.c:360
SCIP_RETCODE GCGgetVarLockData(GCG *gcg, GCG_DECOMP *decomp, SCIP_VAR **vars, int nvars, int nsubproblems, int **subsciplocksdown, int **subsciplocksup, int *masterlocksdown, int *masterlocksup)
Definition: decomp.c:3158
SCIP_RETCODE GCGdecompSetDetectorChain(GCG *gcg, GCG_DECOMP *decomp, GCG_DETECTOR **detectors, int ndetectors)
Definition: decomp.c:1635
int GCGdecompGetDetectorChainSize(GCG_DECOMP *decomp)
Definition: decomp.c:1663
SCIP_Real GCGdecompGetMaxWhiteScore(GCG *gcg, GCG_DECOMP *decdecomp)
Definition: decomp.c:3313
SCIP_RETCODE GCGdecompTransform(GCG *gcg, GCG_DECOMP *decomp)
Definition: decomp.c:2005
void GCGdecompSetConstoblock(GCG_DECOMP *decomp, SCIP_HASHMAP *constoblock)
Definition: decomp.c:1231
GCG_EXPORT SCIP_Real * GCGdecompGetDetectorPctVarsToBorder(GCG_DECOMP *decomp)
Definition: decomp.c:1780
static void incVarsData(SCIP_VAR *var, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars, int nproblems, int i)
Definition: decomp.c:2834
static SCIP_RETCODE assignConstraintsToRepresentatives(GCG *gcg, SCIP_CONS **conss, int nconss, SCIP_Bool *consismaster, SCIP_HASHMAP *constoblock, int *vartoblock, int *nextblock, int *blockrepresentative)
Definition: decomp.c:2520
private methods for working with decomp structures
#define GCG_EXPORT
Definition: def.h:59
#define SCIP_MAXSTRLEN
#define SCIP_Longint
#define SCIP_Bool
#define SCIP_CALL_QUIET(x)
#define MIN(x, y)
#define SCIP_Real
#define MAX(x, y)
#define SCIP_CALL_ABORT(x)
#define SCIP_CALL(x)
#define TRUE
#define FALSE
GCG interface methods.
SCIP_Bool GCGisConsGCGCons(SCIP_CONS *cons)
Definition: misc.c:836
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
GCG_EXPORT int GCGgetNIdenticalBlocks(GCG *gcg, int pricingprobnr)
Definition: relax_gcg.c:4185
SCIP * GCGgetMasterprob(GCG *gcg)
Definition: gcg.cpp:99
GCG_EXPORT SCIP_Bool GCGisPricingprobRelevant(GCG *gcg, int pricingprobnr)
Definition: relax_gcg.c:4132
SCIP_STAGE SCIPgetStage(SCIP *scip)
SCIP_CONS ** SCIPgetConss(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
SCIP_VAR * SCIPfindVar(SCIP *scip, const char *name)
SCIP_CONS * SCIPfindCons(SCIP *scip, const char *name)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
SCIP_RETCODE SCIPhashmapSetImage(SCIP_HASHMAP *hashmap, void *origin, void *image)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
SCIP_Bool GCGisVarRelevant(SCIP_VAR *var)
Definition: scip_misc.c:42
SCIP_Real GCGconsGetRhs(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:109
SCIP_RETCODE GCGconsGetVars(SCIP *scip, SCIP_CONS *cons, SCIP_VAR **vars, int nvars)
Definition: scip_misc.c:487
SCIP_Real GCGconsGetLhs(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:207
SCIP_RETCODE GCGconsGetVals(SCIP *scip, SCIP_CONS *cons, SCIP_Real *vals, int nvals)
Definition: scip_misc.c:618
int GCGconsGetNVars(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:433
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
void SCIPrandomPermuteArray(SCIP_RANDNUMGEN *randnumgen, void **array, int begin, int end)
SCIP_RETCODE SCIPgetConsNVars(SCIP *scip, SCIP_CONS *cons, int *nvars, SCIP_Bool *success)
SCIP_Bool SCIPconsIsDeleted(SCIP_CONS *cons)
SCIP_Bool SCIPconsIsTransformed(SCIP_CONS *cons)
SCIP_RETCODE SCIPgetConsVars(SCIP *scip, SCIP_CONS *cons, SCIP_VAR **vars, int varssize, SCIP_Bool *success)
const char * SCIPconsGetName(SCIP_CONS *cons)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_RETCODE SCIPcaptureCons(SCIP *scip, SCIP_CONS *cons)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPfreeMemoryNull(scip, ptr)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
#define SCIPfreeBufferArrayNull(scip, ptr)
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPvarIsDeleted(SCIP_VAR *var)
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
SCIP_Bool SCIPvarIsTransformed(SCIP_VAR *var)
SCIP_VAR * SCIPvarGetProbvar(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_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIP_IMPLINTTYPE SCIPvarGetImplType(SCIP_VAR *var)
SCIP_RETCODE SCIPgetTransformedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **transvar)
SCIP_RETCODE SCIPcaptureVar(SCIP *scip, SCIP_VAR *var)
#define NULL
#define BMScopyMemoryArray(ptr, source, num)
#define BMSclearMemoryArray(ptr, num)
void SCIPmessageFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr,...)
INLINE Rational & max(Rational &r1, Rational &r2)
INLINE Rational & min(Rational &r1, Rational &r2)
#define SCIPerrorMessage
#define SCIPdebugMessage
#define SCIPdebugPrintf
GCG relaxator.
various SCIP helper methods
SCIP_Real median
Definition: decomp.c:55
SCIP_Real min
Definition: decomp.c:57
SCIP_Real max
Definition: decomp.c:56
SCIP_Real mean
Definition: decomp.c:54
SCIP_Real linkingscore
Definition: pub_decomp.h:66
SCIP_Real borderscore
Definition: pub_decomp.h:64
SCIP_Real totalscore
Definition: pub_decomp.h:67
SCIP_Real densityscore
Definition: pub_decomp.h:65
SCIP_Real * pctconssfromopen
Definition: struct_decomp.h:93
SCIP_Bool presolved
Definition: struct_decomp.h:54
int * nsubscipconss
Definition: struct_decomp.h:62
GCG_DETECTOR ** detectorchain
Definition: struct_decomp.h:83
SCIP_Real * pctvarstoblock
Definition: struct_decomp.h:90
SCIP_HASHMAP * varindex
Definition: struct_decomp.h:80
SCIP_HASHMAP * vartoblock
Definition: struct_decomp.h:74
int * nnewblocks
Definition: struct_decomp.h:94
GCG_DECTYPE type
Definition: struct_decomp.h:82
SCIP_Real * pctvarstoborder
Definition: struct_decomp.h:88
SCIP_Real * pctconsstoblock
Definition: struct_decomp.h:91
SCIP_Real maxwhitescore
Definition: struct_decomp.h:96
SCIP_VAR *** stairlinkingvars
Definition: struct_decomp.h:72
SCIP_Real * pctconsstoborder
Definition: struct_decomp.h:89
GCG_DETECTOR * detector
Definition: struct_decomp.h:84
int sizedetectorchain
Definition: struct_decomp.h:85
int partialdecid
Definition: struct_decomp.h:86
int * nstairlinkingvars
Definition: struct_decomp.h:73
int nlinkingconss
Definition: struct_decomp.h:66
int * nsubscipvars
Definition: struct_decomp.h:58
SCIP_CONS ** linkingconss
Definition: struct_decomp.h:64
SCIP_HASHMAP * consindex
Definition: struct_decomp.h:81
SCIP_HASHMAP * constoblock
Definition: struct_decomp.h:77
SCIP_VAR ** linkingvars
Definition: struct_decomp.h:67
SCIP_VAR *** subscipvars
Definition: struct_decomp.h:56
SCIP_Real * pctvarsfromopen
Definition: struct_decomp.h:92
int nfixedlinkingvars
Definition: struct_decomp.h:70
SCIP_Real * detectorclocktimes
Definition: struct_decomp.h:87
int nlinkingvars
Definition: struct_decomp.h:69
char * detectorchainstring
Definition: struct_decomp.h:95
SCIP_CONS *** subscipconss
Definition: struct_decomp.h:60
Definition: struct_gcg.h:55
structure information for decomposition information in GCG projects
enum Dectype GCG_DECTYPE
Definition: type_decomp.h:57
@ GCG_DECTYPE_UNKNOWN
Definition: type_decomp.h:50
@ GCG_DECTYPE_DIAGONAL
Definition: type_decomp.h:53
@ GCG_DECTYPE_STAIRCASE
Definition: type_decomp.h:52
@ GCG_DECTYPE_ARROWHEAD
Definition: type_decomp.h:51
@ GCG_DECTYPE_BORDERED
Definition: type_decomp.h:54
SCIP_VERBLEVEL_FULL
SCIP_INVALIDDATA
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE
SCIP_STAGE_PRESOLVING
SCIP_STAGE_TRANSFORMED
SCIP_STAGE_INITSOLVE
SCIP_STAGE_PRESOLVED
SCIP_IMPLINTTYPE_NONE
SCIP_VARTYPE_INTEGER
SCIP_VARTYPE_CONTINUOUS
SCIP_VARTYPE_BINARY
SCIP_VARSTATUS_FIXED