Scippy

GCG

Branch-and-Price & Column Generation for Everyone

dec_isomorph.cpp
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 dec_isomorph.cpp
30 *
31 * @brief detector for pricing problems that can be aggregated (uses bliss)
32 * @author Martin Bergner
33 * @author Daniel Peters
34 * @author Jonas Witt
35 * @author Michael Bastubbe
36 *
37 * @note requires package to be installed: BLISS, requires flag to be set: `BLISS=true`
38 *
39 * This detector finds subproblems that can be aggregated thus reducing the symmetry of the problem using color preserving
40 * automorphisms and bliss.
41 */
42
43/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
44/* #define SCIP_DEBUG */
45
46#include "gcg/dec_isomorph.h"
47#include "gcg/pub_decomp.h"
48#include "gcg/cons_decomp.h"
49#include "gcg/scip_misc.h"
50#include "gcg/gcg.h"
53#include "scip/clock.h"
54
55#include "gcg/pub_gcgvar.h"
56#include <cstring>
57#include <cassert>
58#include <algorithm>
59#include <iostream>
60
62
63/* constraint handler properties */
64#define DEC_NAME "isomorph" /**< name of detector */
65#define DEC_DESC "detector for pricing problems suitable for aggregation" /**< description of detector */
66#define DEC_FREQCALLROUND 1 /**< frequency the detector gets called in detection loop ,ie it is called in round r if and only if minCallRound <= r <= maxCallRound AND (r - minCallRound) mod freqCallRound == 0 */
67#define DEC_MAXCALLROUND 0 /**< last round the detector gets called */
68#define DEC_MINCALLROUND 0 /**< first round the detector gets called */
69#define DEC_FREQCALLROUNDORIGINAL 1 /**< frequency the detector gets called in detection loop while detecting the original problem */
70#define DEC_MAXCALLROUNDORIGINAL 0 /**< last round the detector gets called while detecting the original problem */
71#define DEC_MINCALLROUNDORIGINAL 0 /**< first round the detector gets called while detecting the original problem */
72#define DEC_PRIORITY 100 /**< priority of the constraint handler for separation */
73#define DEC_DECCHAR 'I' /**< display character of detector */
74
75#define DEC_ENABLED FALSE /**< should the detection be enabled */
76#define DEC_ENABLEDFINISHING FALSE /**< should the finishing be enabled */
77#define DEC_ENABLEDPOSTPROCESSING FALSE /**< should the postprocessing be enabled */
78#define DEC_SKIP TRUE /**< should the detector be skipped if others found decompositions */
79#define DEC_USEFULRECALL FALSE /**< is it useful to call this detector on a descendant of the propagated partialdec */
80
81#define DEFAULT_MAXDECOMPSEXACT 6 /**< default maximum number of decompositions */
82#define DEFAULT_MAXDECOMPSEXTEND 4 /**< default maximum number of decompositions */
83
84#define SET_MULTIPLEFORSIZETRANSF 12500
85
86/*
87 * Data structures
88 */
89
90/** detector data */
92{
93 SCIP_RESULT result; /**< result pointer to indicate success or failure */
94 int maxdecompsexact; /**< maximum number of decompositions for exact emthod */
95 int maxdecompsextend; /**< maximum number of decompositions for extend method*/
96};
97
98typedef struct struct_hook AUT_HOOK;
99
100/** saves information of the permutation */
102{
103 SCIP_Bool aut; /**< true if there is an automorphism */
104 unsigned int n; /**< number of permutations */
105 SCIP* scip; /**< scip to search for automorphisms */
106 int* conssperm; /**< permutations of conss*/
107 gcg::PARTIALDECOMP* partialdec; /**< partialdec to propagate */
108 gcg::DETPROBDATA* detprobdata; /**< detection process information and data */
109
110 /** constructor for the hook struct*/
111 struct_hook(SCIP_Bool aut, /**< true if there is an automorphism */
112 unsigned int n, /**< number of permutations */
113 SCIP* scip /**< scip to search for automorphisms */
114 );
115
116 /** constructor for the hook struct with a partialdec */
117 struct_hook(SCIP_Bool aut, /**< true if there is an automorphism */
118 unsigned int n, /**< number of permutations */
119 SCIP* scip, /**< scip to search for automorphisms */
120 gcg::PARTIALDECOMP* partialdec, /**< partial decomposition */
121 gcg::DETPROBDATA* detprobdata /**< detection process information and data */
122 );
123
124 ~struct_hook();
125 /** getter for the bool aut */
127
128 /** setter for the bool aut */
129 void setBool(SCIP_Bool aut);
130
131 /** getter for the SCIP */
132 SCIP* getScip();
133
134 /** getter for the partialdec */
136
137 /** getter for the detprobdata */
139};
140
142{
143 return this->scip;
144}
145
147{
148 return this->partialdec;
149}
150
152{
153 return this->detprobdata;
154}
155
157{
158 return aut;
159}
160
161void struct_hook::setBool( SCIP_Bool aut_ )
162{
163 aut = aut_;
164}
165
166
167
168
169/** method to calculate the greatest common divisor */
170static
171int gcd(int a, int b) {
172 return b == 0 ? a : gcd(b, a % b);
173}
174
175/** constructor of the hook struct */
177 SCIP_Bool aut_, /**< true if there is an automorphism */
178 unsigned int n_, /**< number of permutations */
179 SCIP* scip_ /**< array of scips to search for automorphisms */
180 ) : conssperm(NULL)
181{
182 aut = aut_;
183 n = n_;
184 scip = scip_;
188}
189
190/** constructor of the hook struct */
192 SCIP_Bool aut_, /**< true if there is an automorphism */
193 unsigned int n_, /**< number of permutations */
194 SCIP* scip_, /**< array of scips to search for automorphisms */
195 gcg::PARTIALDECOMP* partialdec_, /**< partialdec to propagate */
196 gcg::DETPROBDATA* detprobdata_ /**< detection process information and data */
197 ) : conssperm(NULL)
198{
199 aut = aut_;
200 n = n_;
201 scip = scip_;
202 SCIP_CALL_ABORT( SCIPallocMemoryArray(scip, &conssperm, detprobdata_->getNConss() ) ); /*lint !e666*/
203 partialdec = partialdec_;
204 detprobdata = detprobdata_;
205}
206
208{ /*lint -esym(1540,struct_hook::conssperm) */
209 if( conssperm != NULL )
211 conssperm = NULL;
212 scip = NULL;
213}
214
215/** hook function to save the permutation of the graph */
216static
218 void* user_param, /**< data structure to save hashmaps with permutation */
219 unsigned int N, /**< number of permutations */
220 const unsigned int* aut /**< array of permutations */
221 )
222{ /*lint -e715*/
223 int i;
224 int nconss;
225 AUT_HOOK* hook = (AUT_HOOK*) user_param;
226 int auti;
227 int ind;
228 gcg::PARTIALDECOMP* partialdec;
229 gcg::DETPROBDATA* detprobdata;
230
231 partialdec = hook->getPartialdec();
232 detprobdata = hook->getDetprobdata() ;
233 assert(partialdec != NULL);
234 assert(detprobdata != NULL);
235 nconss = partialdec->getNOpenconss();
236
237 for( i = 0; i < nconss; i++ )
238 {
239 SCIP_CONS* cons = detprobdata->getCons(partialdec->getOpenconss()[i]);
240 assert(aut[i] < INT_MAX);
241 if( (size_t) i != aut[i])
242 {
243 auti = (int) aut[i];
244
245 SCIPdebugMessage("%d <%s> <-> %d <%s>\n", i, SCIPconsGetName(cons), auti,
246 SCIPconsGetName(detprobdata->getCons(partialdec->getOpenconss()[auti])));
247
248 ind = MIN(i, auti);
249
250 if( hook->conssperm[i] != -1)
251 ind = MIN(ind, hook->conssperm[i]);
252 if( hook->conssperm[auti] != -1 )
253 ind = MIN(ind, hook->conssperm[auti]);
254
255 hook->conssperm[i] = ind;
256 hook->conssperm[auti] = ind;
257 hook->setBool(TRUE);
258 }
259 }
260}
261
262static
264 SCIP* scip, /**< SCIP data structure */
265 AUT_COLOR* colorinfo, /**< struct to save intermediate information */
266 int nconss, /**< number of constraints */
267 int nvars /**< number of variables */
268 )
269{
270 SCIP_CALL( SCIPallocMemoryArray(scip, &colorinfo->ptrarraycoefs, nvars) );
271 SCIP_CALL( SCIPallocMemoryArray(scip, &colorinfo->ptrarrayvars, nvars) );
272 SCIP_CALL( SCIPallocMemoryArray(scip, &colorinfo->ptrarrayconss, nconss) );
273 colorinfo->alloccoefsarray = nvars;
274 return SCIP_OKAY;
275}
276
277/** destructor for colorinfo */
278static
280 SCIP* scip, /**< SCIP data structure */
281 AUT_COLOR* colorinfo /**< struct to save intermediate information */
282)
283{
284 int i;
285
286 for( i = 0; i < colorinfo->lenvarsarray; i++ )
287 {
288 AUT_VAR* svar = (AUT_VAR*) colorinfo->ptrarrayvars[i];
289 delete svar;
290 }
291 for( i = 0; i < colorinfo->lenconssarray; i++ )
292 {
293 AUT_CONS* scons = (AUT_CONS*) colorinfo->ptrarrayconss[i];
294 delete scons;
295 }
296 for( i = 0; i < colorinfo->lencoefsarray; i++ )
297 {
298 AUT_COEF* scoef = (AUT_COEF*) colorinfo->ptrarraycoefs[i];
299 delete scoef;
300 }
301
302 SCIPfreeMemoryArray(scip, &colorinfo->ptrarraycoefs);
303 SCIPfreeMemoryArray(scip, &colorinfo->ptrarrayconss);
304 SCIPfreeMemoryArray(scip, &colorinfo->ptrarrayvars);
305}
306
307/** set up a help structure for graph creation (for partialdecs) */
308static
310 SCIP* scip, /**< SCIP to compare */
311 AUT_COLOR* colorinfo, /**< data structure to save intermediate data */
312 SCIP_RESULT* result, /**< result pointer to indicate success or failure */
313 gcg::PARTIALDECOMP* partialdec, /**< partialdec to set up help structure for */
314 gcg::DETPROBDATA* detprobdata /**< detection process information and data */
315 )
316{ /*lint -esym(593,scoef) */
317 int i;
318 int j;
319 int nconss;
320 int nvars;
321 AUT_COEF* scoef;
322 AUT_CONS* scons;
323 SCIP_Bool added;
324 SCIP_Bool onlysign;
325
326 //allocate max n of coefarray, varsarray, and boundsarray in scip
327 nconss = partialdec->getNOpenconss();
328 nvars = partialdec->getNVars();
329 SCIP_CALL( allocMemory(scip, colorinfo, nconss, nvars) );
330
331 onlysign = colorinfo->getOnlySign();
332
333 //save the properties of variables in a struct array and in a sorted pointer array
334 for( i = 0; i < nvars; i++ )
335 {
336 SCIP_VAR* var = detprobdata->getVar(i);
337 AUT_VAR* svar = new AUT_VAR(scip, var);
338 //add to pointer array iff it doesn't exist
339 SCIP_CALL( colorinfo->insert(svar, &added) );
340 SCIPdebugMessage("%s color %d %d\n", SCIPvarGetName(var), colorinfo->get(*svar), colorinfo->color);
341 //otherwise free allocated memory
342 if( !added )
343 delete svar;
344 }
345
346 //save the properties of constraints in a struct array and in a sorted pointer array
347 for( i = 0; i < nconss && *result == SCIP_SUCCESS; i++ )
348 {
349 int consindex = partialdec->getOpenconss()[i];
350 SCIP_CONS* cons = detprobdata->getCons(consindex);
351
352 int ncurvars = detprobdata->getNVarsForCons(consindex);
353 if( ncurvars == 0 )
354 continue;
355
356 scons = new AUT_CONS(scip, cons);
357 //add to pointer array iff it doesn't exist
358 SCIPdebugMessage("nconss %d %d\n", nconss, *result);
359 SCIP_CALL( colorinfo->insert(scons, &added) );
360 SCIPdebugMessage("%s color %d %d\n", SCIPconsGetName(cons), colorinfo->get(*scons), colorinfo->color);
361 //otherwise free allocated memory
362 if( !added )
363 delete scons;
364
365 //save the properties of variables of the constraints in a struct array and in a sorted pointer array
366 for( j = 0; j < ncurvars; j++ )
367 {
368 added = FALSE;
369
370 if( !onlysign )
371 {
372 scoef = new AUT_COEF(scip, detprobdata->getValsForCons(consindex)[j]);
373 }
374 else
375 {
376 if( SCIPisPositive(scip, detprobdata->getValsForCons(consindex)[j]) )
377 scoef = new AUT_COEF(scip, 1.0);
378 else if( SCIPisNegative(scip, detprobdata->getValsForCons(consindex)[j]) )
379 scoef = new AUT_COEF(scip, -1.0);
380 else
381 scoef = new AUT_COEF(scip, 0.0);
382 }
383
384 //test, whether the coefficient is not zero
385 if( !SCIPisZero(scip, scoef->getVal()) )
386 {
387 //add to pointer array iff it doesn't exist
388 SCIP_CALL( colorinfo->insert(scoef, &added) );
389 SCIPdebugMessage("%f color %d %d\n", scoef->getVal(), colorinfo->get(*scoef), colorinfo->color);
390 }
391 //otherwise free allocated memory
392 if( !added )
393 delete scoef;
394
395 }
396 }
397 return SCIP_OKAY;
398}
399
400/** create a graph out of an array of scips (for partialdecs) */
401static
403 SCIP* scip, /**< SCIP to compare */
404 AUT_COLOR colorinfo, /**< data structure to save intermediate data */
405 AUT_GRAPH* graph, /**< graph needed for discovering isomorphism */
406 SCIP_RESULT* result, /**< result pointer to indicate success or failure */
407 gcg::PARTIALDECOMP* partialdec, /**< partialdec to create graph for */
408 gcg::DETPROBDATA* detprobdata /**< detection process information and data */
409 )
410{
411 int i;
412 int j;
413 int z;
414 int nvars;
415 int nconss;
416 int ncurvars;
417 int curvar;
418 int color;
419 unsigned int nnodes;
420 unsigned int currentnode;
421 SCIP_Bool onlysign;
422 unsigned int nconsvarpairs;
423 currentnode = 0;
424 nconss = partialdec->getNOpenconss();
425 nvars = partialdec->getNVars();
426 z = 0;
427 onlysign = colorinfo.getOnlySign();
428 nconsvarpairs = 0;
429
430 for( i = 0; i < nconss; i++ )
431 {
432 nconsvarpairs += detprobdata->getNVarsForCons(partialdec->getOpenconss()[i]);
433 }
434
435 nnodes = nconss + nvars + nconsvarpairs;
436 graph->init(scip, nnodes);
437
438 //add a node for every constraint
439 for( i = 0; i < nconss && *result == SCIP_SUCCESS; i++ )
440 {
441 ncurvars = detprobdata->getNVarsForCons(partialdec->getOpenconss()[i]);
442 SCIP_CONS* cons = detprobdata->getCons(partialdec->getOpenconss()[i]);
443
444 AUT_CONS scons(scip, cons);
445 color = colorinfo.get(scons);
446
447 if( color == -1 )
448 {
449 *result = SCIP_DIDNOTFIND;
450 break;
451 }
452
453 assert(color >= 0);
454 graph->setColor(currentnode, color);
455 currentnode++;
456 }
457 //add a node for every variable
458 for( i = 0; i < nvars && *result == SCIP_SUCCESS; i++ )
459 {
460 SCIP_VAR* var = detprobdata->getVar(i);
461 AUT_VAR svar(scip, var);
462 color = colorinfo.get(svar);
463
464 if( color == -1 )
465 {
466 *result = SCIP_DIDNOTFIND;
467 break;
468 }
469 graph->setColor(currentnode, colorinfo.getLenCons() + color);
470 currentnode++;
471 }
472 //connecting the nodes with an additional node in the middle
473 //it is necessary, since only nodes have colors
474 for( i = 0; i < nconss && *result == SCIP_SUCCESS; i++ )
475 {
476 int consindex = partialdec->getOpenconss()[i];
477 SCIP_CONS* cons = detprobdata->getCons(consindex);
478 AUT_CONS scons(scip, cons);
479 ncurvars = detprobdata->getNVarsForCons(partialdec->getOpenconss()[i]);
480 if( ncurvars == 0 )
481 continue;
482
483 for( j = 0; j < ncurvars; j++ )
484 {
485 int varindex = detprobdata->getVarsForCons(consindex)[j];
486 SCIP_VAR* var = detprobdata->getVar(varindex);
487
488
489// if( SCIPgetStage(scip) >= SCIP_STAGE_TRANSFORMED)
490// SCIPgetProbvarSum(scip, &(curvars[j]), &(curvals[j]), &constant);
491
492 SCIP_Real val;
493
494 if( !onlysign )
495 {
496 val = detprobdata->getValsForCons(consindex)[j];
497 }
498 else
499 {
500 if( SCIPisPositive(scip, detprobdata->getValsForCons(consindex)[j]) )
501 val = 1.0;
502 else if( SCIPisNegative(scip, detprobdata->getValsForCons(consindex)[j]) )
503 val = -1.0;
504 else
505 val = 0.0;
506 }
507 *result = SCIP_SUCCESS;
508
509 AUT_COEF scoef(scip, val);
510 AUT_VAR svar(scip, var);
511
512 color = colorinfo.get(scoef);
513
514 if( color == -1 )
515 {
516 *result = SCIP_DIDNOTFIND;
517 break;
518 }
519
520 curvar = SCIPvarGetProbindex(var);
521 graph->setColor(currentnode, colorinfo.getLenCons() + colorinfo.getLenVar() + color); /*lint !e864 */
522 currentnode++;
523 graph->addEdge(i, nconss + nvars + z);
524 graph->addEdge(nconss + nvars + z, nconss + curvar);
526 "nz: c <%s> (id: %d, colour: %d) -> nz (id: %d) (value: %f, colour: %d) -> var <%s> (id: %d, colour: %d) \n",
527 SCIPconsGetName(cons), i, colorinfo.get(scons),
528 nconss + nvars + z, scoef.getVal(),
529 color + colorinfo.getLenCons() + colorinfo.getLenVar(), /*lint !e864 */
530 SCIPvarGetName(var), nconss + curvar,
531 colorinfo.get(svar) + colorinfo.getLenCons()); /*lint !e864 */
532 z++;
533 }
534 }
535 SCIPdebugMessage("Iteration 1: currentnode = %ud, Cons = %d, Vars = %d\n", currentnode, colorinfo.getLenCons(), colorinfo.getLenVar()); /*lint !e864 */
536 assert(*result == SCIP_SUCCESS && currentnode == graph->getNVertices());
537
538 //free all allocated memory
539 freeMemory(scip, &colorinfo);
540 return SCIP_OKAY;
541}
542
543
544/** creates a partialdec with provided constraints in the master
545 * The function will put the remaining constraints in one or more pricing problems
546 * depending on whether the subproblems decompose with no variables in common.
547 */
549 SCIP* scip, /**< SCIP data structure */
550 gcg::PARTIALDECOMP** newPartialdec, /**< partialdec data structure */
551 int* masterconss, /**< constraints to be put in the master */
552 int nmasterconss, /**< number of constraints in the master */
553 gcg::PARTIALDECOMP* partialdec, /**< partialdec to propagate */
554 gcg::DETPROBDATA* detprobdata, /**< detection process information and data */
555 SCIP_Bool exact /** does this partialdec stems from exact graph construction ( or was onlysign = TRUE ) was used */
556 )
557{
558
559
560 char decinfo[SCIP_MAXSTRLEN];
561 int nconss;
562 int nvars;
563 int nblocks;
564 int* blockrepresentative = NULL;
565 int nextblock = 1;
566 SCIP_Bool* consismaster = NULL;
567 int i, j;
568 int* vartoblock = NULL;
569 int ncurvars;
570
571 std::vector<int> constoblock( detprobdata->getNConss(), -1);
572 std::vector<int> newconstoblock( detprobdata->getNConss(), -1);
573
574 assert(scip != NULL);
575 assert(nmasterconss == 0 || masterconss != NULL);
577
578 nconss = partialdec->getNOpenconss();
579 nvars = partialdec->getNVars();
580
581 assert( nmasterconss <= nconss );
582
583 nblocks = nconss-nmasterconss+1;
584 assert(nblocks > 0);
585
586 SCIP_CALL( SCIPallocMemoryArray(scip, &blockrepresentative, nblocks) );
587 SCIP_CALL( SCIPallocMemoryArray(scip, &consismaster, nconss) );
588 SCIP_CALL( SCIPallocMemoryArray(scip, &vartoblock, nvars) );
589
590 for( i = 0; i < nmasterconss; ++i )
591 {
592 constoblock[masterconss[i]] = nblocks+1;
593 }
594
595 for( i = 0; i < nconss; ++i )
596 {
597 consismaster[i] = ( constoblock[partialdec->getOpenconss()[i]] != -1 );
598 }
599
600 for( i = 0; i < nvars; ++i )
601 {
602 vartoblock[i] = -1;
603 }
604
605 for( i = 0; i < nblocks; ++i )
606 {
607 blockrepresentative[i] = -1;
608 }
609
610 /* assign constraints to representatives */
611
612 /* go through the all constraints */
613 for( i = 0; i < nconss; ++i )
614 {
615 int consblock;
616 int cons = partialdec->getOpenconss()[i];
617
618 if( consismaster[i] )
619 continue;
620
621 /* get variables of constraint; ignore empty constraints */
622 ncurvars = detprobdata->getNVarsForCons(partialdec->getOpenconss()[i]);
623 assert(ncurvars >= 0);
624
625 assert( constoblock[cons] == -1 );
626
627 /* if there are no variables, put it in the first block, otherwise put it in the next block */
628 if( ncurvars == 0 )
629 consblock = -1;
630 else
631 consblock = nextblock;
632
633 /* go through all variables */
634 for( j = 0; j < ncurvars; ++j )
635 {
636 int var;
637 int varblock;
638 var = detprobdata->getVarsForCons(cons)[j];
639
640 assert(var >= 0);
641
642 /** @todo what about deleted variables? */
643 /* get block of variable */
644 varblock = vartoblock[var];
645
646 /* if variable is already assigned to a block, assign constraint to that block */
647 if( varblock > -1 && varblock != consblock )
648 {
649 consblock = MIN(consblock, blockrepresentative[varblock]);
650 SCIPdebugPrintf("still in block %d.\n", varblock);
651 }
652 else if( varblock == -1 )
653 {
654 /* if variable is free, assign it to the new block for this constraint */
655 varblock = consblock;
656 assert(varblock > 0);
657 assert(varblock <= nextblock);
658 vartoblock[var] = varblock;
659 SCIPdebugPrintf("new in block %d.\n", varblock);
660 }
661 else
662 {
663 assert((varblock > 0) && (consblock == varblock));
664 SCIPdebugPrintf("no change.\n");
665 }
666
667 SCIPdebugPrintf("VARINDEX: %d (%d)\n", var, vartoblock[var]);
668 }
669
670 /* if the constraint belongs to a new block, mark it as such */
671 if( consblock == nextblock )
672 {
673 assert(consblock > 0);
674 blockrepresentative[consblock] = consblock;
675 assert(blockrepresentative[consblock] > 0);
676 assert(blockrepresentative[consblock] <= nextblock);
677 ++(nextblock);
678 }
679
680 SCIPdebugMessage("Cons %s will be in block %d (next %d)\n", SCIPconsGetName(detprobdata->getCons(cons)), consblock, nextblock);
681
682 for( j = 0; j < ncurvars; ++j )
683 {
684 int var;
685 int oldblock;
686 var = detprobdata->getVarsForCons(cons)[j];
687
688 oldblock = vartoblock[var];
689 assert((oldblock > 0) && (oldblock <= nextblock));
690
691 SCIPdebugMessage("\tVar %s ", SCIPvarGetName(detprobdata->getVar(var)));
692 if( oldblock != consblock )
693 {
694 SCIPdebugPrintf("reset from %d to block %d.\n", oldblock, consblock);
695 vartoblock[var] = consblock;
696 SCIPdebugPrintf("VARINDEX: %d (%d)\n", var, consblock);
697
698 if( (blockrepresentative[oldblock] != -1) && (blockrepresentative[oldblock] > blockrepresentative[consblock]) )
699 {
700 int oldrepr;
701 oldrepr = blockrepresentative[oldblock];
702 SCIPdebugMessage("\t\tBlock representative from block %d changed from %d to %d.\n", oldblock, blockrepresentative[oldblock], consblock);
703 assert(consblock > 0);
704 blockrepresentative[oldblock] = consblock;
705 if( (oldrepr != consblock) && (oldrepr != oldblock) )
706 {
707 blockrepresentative[oldrepr] = consblock;
708 SCIPdebugMessage("\t\tBlock representative from block %d changed from %d to %d.\n", oldrepr, blockrepresentative[oldrepr], consblock);
709 }
710 }
711 }
712 else
713 {
714 SCIPdebugPrintf("will not be changed from %d to %d.\n", oldblock, consblock);
715 }
716 }
717 assert(consblock >= 1 || consblock == -1);
718 assert(consblock <= nextblock);
719
720 /* store the constraint block */
721 if( consblock != -1 )
722 {
723 SCIPdebugMessage("cons %s in block %d\n", SCIPconsGetName(detprobdata->getCons(cons)), consblock);
724 constoblock[cons] = consblock;
725 }
726 else
727 {
728 SCIPdebugMessage("ignoring %s\n", SCIPconsGetName(detprobdata->getCons(cons)));
729 }
730 }
731
732 /* postprocess blockrepresentatives */
733
734 int tempblock = 1;
735 int maxblock = nextblock;
736
737 assert(maxblock >= 1);
738 assert(blockrepresentative != NULL );
739 //SCIPdebugPrintf("Blocks: ");
740
741 for( i = 1; i < maxblock; ++i )
742 {
743 /* forward replace the representatives */
744 assert(blockrepresentative[i] >= 0);
745 assert(blockrepresentative[i] < maxblock);
746 if( blockrepresentative[i] != i )
747 blockrepresentative[i] = blockrepresentative[blockrepresentative[i]];
748 else
749 {
750 blockrepresentative[i] = tempblock;
751 ++tempblock;
752 }
753 /* It is crucial that this condition holds */
754 assert(blockrepresentative[i] <= i);
755 // SCIPdebugPrintf("%d ", blockrepresentative[i]);
756 }
757// SCIPdebugPrintf("\n");
758
759 /* convert temporary data to detectordata */
760
761 /* fillout Constoblock */
762 /* convert temporary data to detectordata */
763 for( i = 0; i < nconss; ++i )
764 {
765 int consblock;
766
767 int cons = partialdec->getOpenconss()[i];
768
769 if( consismaster[i] )
770 {
771 /* notation is misleading: masterconss are only potential master constraints */
772 /* SCIP_CALL( SCIPhashmapInsert(newconstoblock, (void*) (size_t) cons, (void*) (size_t) (nblocks+1)) ); */
773 continue;
774 }
775
776 if( constoblock[cons] == -1)
777 continue;
778
779 consblock = constoblock[cons]; /*lint !e507*/
780 assert(consblock > 0);
781 consblock = blockrepresentative[consblock];
782 assert(consblock <= nblocks);
783 newconstoblock[cons] = consblock;
784 SCIPdebugMessage("%d %s\n", consblock, SCIPconsGetName(detprobdata->getCons(cons)));
785 }
786 (*newPartialdec) = new gcg::PARTIALDECOMP(partialdec);
787 SCIP_CALL( (*newPartialdec)->assignPartialdecFromConstoblockVector(newconstoblock, nblocks) );
788
789 (*newPartialdec)->considerImplicits();
790 (*newPartialdec)->refineToBlocks();
791
792 if( exact )
793 (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, "isomorph\\_exact");
794 else
795 (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, "isomorph\\_extended" );
796 (*newPartialdec)->addDetectorChainInfo(decinfo);
797
798
799
800 //(*newPartialdec)->showScatterPlot(detprobdata);
801
802 SCIPfreeMemoryArray(scip, &vartoblock);
803 SCIPfreeMemoryArray(scip, &consismaster);
804 SCIPfreeMemoryArray(scip, &blockrepresentative);
805
806 return SCIP_OKAY;
807}
808
809/** destructor of detector to free user data (called when GCG is exiting) */
810static
811GCG_DECL_FREEDETECTOR(detectorFreeIsomorph)
812{ /*lint --e{715}*/
813 GCG_DETECTORDATA *detectordata;
814
815 assert(gcg != NULL);
816 assert(detector != NULL);
817
818 assert(strcmp(GCGdetectorGetName(detector), DEC_NAME) == 0);
819
820 detectordata = GCGdetectorGetData(detector);
821 assert(detectordata != NULL);
822
823 SCIPfreeMemory(GCGgetOrigprob(gcg), &detectordata);
824
825 return SCIP_OKAY;
826}
827
828/** detector initialization method (called after problem was transformed) */
829static
830GCG_DECL_INITDETECTOR(detectorInitIsomorph)
831{ /*lint --e{715}*/
832 GCG_DETECTORDATA *detectordata;
833
834 assert(gcg != NULL);
835 assert(detector != NULL);
836
837 assert(strcmp(GCGdetectorGetName(detector), DEC_NAME) == 0);
838
839 detectordata = GCGdetectorGetData(detector);
840 assert(detectordata != NULL);
841
842 detectordata->result = SCIP_SUCCESS;
843
844 return SCIP_OKAY;
845}
846
847/** renumbers the permutations from 0 to n-1 and returns the number of permutations
848 * @return the number of permutations
849 */
851 int* permutation, /**< the permutation */
852 int permsize /**< size of the permutation */
853)
854{
855 // renumbering from 0 to number of permutations
856 int nperms = -1;
857
858 for( int i = 0; i < permsize; i++ )
859 {
860 SCIPdebugMessage("%d: %d -> ", i, permutation[i]);
861 if( permutation[i] == -1 )
862 {
863 SCIPdebugPrintf("%d\n", permutation[i]);
864 continue;
865 }
866
867 if( permutation[i] > nperms && permutation[permutation[i]] > nperms )
868 {
869 nperms++;
870 permutation[i] = nperms;
871 }
872 else
873 {
874 permutation[i] = permutation[permutation[i]];
875 }
876 SCIPdebugPrintf("%d\n", permutation[i]);
877 }
878
879 return nperms+1;
880}
881
882/** collapses the permutation, if possible */
884 int* permutation, /**< the permutation */
885 int permsize /**< size of the permutation */
886)
887{
888 int tmp = 0;
889 // assign to a permutation circle only one number
890 for( int i = 0; i < permsize; i++ )
891 {
892 if( permutation[i] != -1 && permutation[i] != i )
893 {
894 tmp = permutation[i];
895 permutation[i] = permutation[tmp];
896 }
897 SCIPdebugMessage("%d %d\n",i, permutation[i]);
898
899 }
900}
901
902/** method to enumerate all subsets */
903static
904std::vector< std::vector<int> > getAllSubsets(std::vector<int> set)
905{
906 std::vector< std::vector<int> > subset;
907 std::vector<int> empty;
908 subset.push_back( empty );
909
910 for ( size_t i = 0; i < set.size(); ++i )
911 {
912 std::vector< std::vector<int> > subsetTemp = subset;
913
914 for (size_t j = 0; j < subsetTemp.size(); ++j)
915 subsetTemp[j].push_back( set[i] );
916
917 for (size_t j = 0; j < subsetTemp.size(); ++j)
918 subset.push_back( subsetTemp[j] );
919 }
920 return subset;
921}
922
923/** reorder such that the best permutation is represented by 0, the second best by 1, etc. */
925 GCG* gcg, /**< GCG data structure */
926 gcg::DETPROBDATA* detprobdata, /**< detection process information and data */
927 int* permutation, /**< the permutation */
928 int permsize, /**< size of the permutation */
929 int nperms /**< number of permutations */
930)
931{
932 SCIP* scip;
933 int i;
934 int* count = NULL;
935 int* order = NULL;
936 int* invorder = NULL;
937
938 assert(gcg != NULL);
939 assert(permutation != NULL);
940 assert(permsize > 0);
941 assert(nperms > 0);
942
944 SCIP_CALL( SCIPallocBufferArray(scip, &count, nperms) );
945 SCIP_CALL( SCIPallocBufferArray(scip, &order, nperms) );
946 SCIP_CALL( SCIPallocBufferArray(scip, &invorder, nperms) );
947 BMSclearMemoryArray(count, nperms);
948 BMSclearMemoryArray(order, nperms);
949 BMSclearMemoryArray(invorder, nperms);
950
951 /* initialize order array that will give a mapping from new to old representatives */
952 for( i = 0; i < nperms; ++i )
953 {
954 order[i] = i;
955 }
956
957 /* count sizes of orbits */
958 for( i = 0; i < permsize; ++i )
959 {
960 if( permutation[i] >= 0 )
961 {
962 count[permutation[i]] += 1;
963
964 SCIPdebugMessage("permutation[i] = %d; count %d\n", permutation[i], count[permutation[i]]);
965 }
966 }
967
968 /* sort count and order array */
969 SCIPsortDownIntInt(count, order, nperms);
970
971#ifdef SCIP_DEBUG
972
973 for( i = 0; i < nperms; ++i )
974 {
975 SCIPdebugMessage("count[%d] = %d, order[%d] = %d\n", i, count[i], i, order[i]);
976 }
977#endif
978
979 /* compute invorder array that gives a mapping from old to new representatives */
980 for( i = 0; i < nperms; ++i )
981 {
982 invorder[order[i]] = i;
983 SCIPdebugMessage("invorder[%d] = %d\n", order[i], invorder[order[i]]);
984 }
985
986 SCIPdebugMessage("Best permutation with orbit of size %d, best %d\n", count[0], order[0]);
987
988 /* update representatives of constraints */
989 for( i = 0; i < permsize; ++i )
990 {
991 if( permutation[i] >= 0 )
992 permutation[i] = invorder[permutation[i]];
993 }
994
995
996 std::vector<int> orbitsizes(0);
997
998 /* compute invorder array that gives a mapping from old to new representatives */
999 for( i = 0; i < nperms; ++i )
1000 {
1001 int orbitsize;
1002 orbitsize = count[i];
1003
1004 /* find orbitsize or not */
1005 std::vector<int>::const_iterator orbitsizesIter = orbitsizes.begin();
1006 for(; orbitsizesIter != orbitsizes.end(); ++orbitsizesIter)
1007 {
1008 if(*orbitsizesIter == orbitsize)
1009 break;
1010 }
1011
1012 if( orbitsizesIter == orbitsizes.end() )
1013 {
1015
1016 orbitsizes.push_back(orbitsize);
1017 }
1018 }
1019 std::vector< std::vector<int> > subsetsOfOrbitsizes = getAllSubsets(orbitsizes);
1020
1021 for(size_t subset = 0; subset < subsetsOfOrbitsizes.size(); ++subset)
1022 {
1023 int greatestCD = 1;
1024
1025 if(subsetsOfOrbitsizes[subset].size() == 0 || subsetsOfOrbitsizes[subset].size() == 1)
1026 continue;
1027
1028 greatestCD = gcd(subsetsOfOrbitsizes[subset][0], subsetsOfOrbitsizes[subset][1] );
1029
1030 for( size_t j = 2; j < subsetsOfOrbitsizes[subset].size() ; ++j)
1031 {
1032 greatestCD = gcd( greatestCD, subsetsOfOrbitsizes[subset][j] );
1033 }
1034
1036 }
1037
1038 SCIPfreeBufferArray(scip, &invorder);
1039 SCIPfreeBufferArray(scip, &order);
1040 SCIPfreeBufferArray(scip, &count);
1041
1042 return SCIP_OKAY;
1043}
1044
1045
1046/** detection function of isomorph detector for partialdecs */
1047static
1049 GCG* gcg, /**< GCG data structure */
1050 PARTIALDEC_DETECTION_DATA* detectiondata, /**< detection data */
1051 GCG_DETECTORDATA* detectordata, /**< detector data structure */
1052 SCIP_RESULT* result, /**< pointer to store result */
1053 SCIP_Bool onlysign, /**< use only sign of coefficients instead of coefficients? */
1054 int maxdecomps /**< maximum number of new decompositions */
1055 )
1056{
1057 SCIP_CLOCK* temporaryClock;
1059 SCIP_CALL_ABORT( SCIPcreateClock(scip, &temporaryClock) );
1060 SCIP_CALL_ABORT( SCIPstartClock(scip, temporaryClock) );
1061
1062 AUT_GRAPH graph;
1063 AUT_HOOK *ptrhook;
1064 AUT_COLOR *colorinfo;
1065 gcg::PARTIALDECOMP* partialdec = detectiondata->workonpartialdec;
1066 gcg::DETPROBDATA* detprobdata = detectiondata->detprobdata;
1067
1068 int nconss = partialdec->getNOpenconss();
1069 int i;
1070
1071 detectordata->result = SCIP_SUCCESS;
1072
1073 colorinfo = new AUT_COLOR();
1074
1075 colorinfo->setOnlySign(onlysign);
1076
1077
1078 if( !onlysign )
1079 SCIPverbMessage(scip, SCIP_VERBLEVEL_NORMAL, NULL, "Detecting aggregatable structure: ");
1080 else
1081 SCIPverbMessage(scip, SCIP_VERBLEVEL_NORMAL, NULL, "Detecting almost aggregatable structure: ");
1082
1083 SCIP_CALL( setupArrays(scip, colorinfo, &detectordata->result, partialdec, detprobdata) );
1084 SCIP_CALL( createGraph(scip, *colorinfo, &graph, &detectordata->result, partialdec, detprobdata) );
1085
1086 ptrhook = new AUT_HOOK(FALSE, graph.getNVertices(), scip, partialdec, detprobdata);
1087 for( i = 0; i < nconss; i++ )
1088 {
1089 ptrhook->conssperm[i] = -1;
1090 }
1091
1092 graph.findAutomorphisms(ptrhook, fhookForPartialdecs, 0u, 0u);
1093
1094 if( !ptrhook->getBool() )
1095 detectordata->result = SCIP_DIDNOTFIND;
1096
1097 if( detectordata->result == SCIP_SUCCESS )
1098 {
1099 int nperms;
1100 int nmasterconss;
1101 int* masterconss = NULL;
1102 int p;
1103
1104 // assign to a permutation circle only one number
1105 collapsePermutation(ptrhook->conssperm, nconss);
1106 // renumbering from 0 to number of permutations
1107 nperms = renumberPermutations(ptrhook->conssperm, nconss);
1108
1109 // reorder decomposition (corresponding to orbit size)
1110 SCIP_CALL( reorderPermutations(gcg, detprobdata, ptrhook->conssperm, nconss, nperms) );
1111
1112 SCIP_CALL( SCIPreallocMemoryArray(scip, &(detectiondata->newpartialdecs), detectiondata->nnewpartialdecs + MIN(maxdecomps, nperms)) ); /*lint !e506*/
1113
1114 int pos = detectiondata->nnewpartialdecs;
1115
1116 for( p = 0; p < nperms && pos < maxdecomps; ++p )
1117 {
1118 SCIP_CALL( SCIPallocMemoryArray(scip, &masterconss, nconss) );
1119
1120 SCIPdebugMessage("masterconss of partialdec %d:\n", p);
1121
1122 nmasterconss = 0;
1123 for( i = 0; i < nconss; i++ )
1124 {
1125 if( p != ptrhook->conssperm[i] )
1126 {
1127 masterconss[nmasterconss] = partialdec->getOpenconss()[i];
1128 SCIPdebugMessage("%s\n", SCIPconsGetName(detprobdata->getCons(masterconss[nmasterconss])));
1129 nmasterconss++;
1130 }
1131 }
1132 SCIPdebugMessage("%d\n", nmasterconss);
1133
1134 if( nmasterconss < nconss )
1135 {
1136 SCIP_Bool isduplicate;
1137 int q;
1138
1139 SCIP_CALL( createPartialdecFromMasterconss(scip, &(detectiondata->newpartialdecs[pos]), masterconss, nmasterconss, partialdec, detprobdata, !onlysign) );
1140
1141 isduplicate = FALSE;
1142 for( q = 0; q < pos && !isduplicate; ++q )
1143 {
1144 SCIP_CALL( detectiondata->newpartialdecs[pos]->isEqual(detectiondata->newpartialdecs[q], &isduplicate, TRUE) );
1145 }
1146
1147 if( isduplicate )
1148 {
1149 delete detectiondata->newpartialdecs[pos];
1150 }
1151 else
1152 {
1153 ++pos;
1154 }
1155
1156 SCIPfreeMemoryArray(scip, &masterconss);
1157 }
1158
1159 else
1160 {
1161 SCIPfreeMemoryArray(scip, &masterconss);
1162 SCIP_CALL_ABORT( SCIPstopClock(scip, temporaryClock ) );
1163 continue;
1164 }
1165 }
1166 detectiondata->nnewpartialdecs = pos;
1167
1168 if( detectiondata->nnewpartialdecs > 0 )
1169 {
1170 SCIP_CALL( SCIPreallocMemoryArray(scip, &(detectiondata->newpartialdecs), detectiondata->nnewpartialdecs) );
1171 }
1172
1173 SCIPverbMessage(scip, SCIP_VERBLEVEL_NORMAL, NULL, "found %d (new) decompositions.\n", detectiondata->nnewpartialdecs);
1174 }
1175 else
1176 {
1178 }
1179
1180 delete colorinfo;
1181 delete ptrhook;
1182 graph.destroy();
1183
1184 SCIP_CALL_ABORT( SCIPstopClock(scip, temporaryClock ) );
1185
1186 if( detectiondata->nnewpartialdecs == 0 )
1187 {
1188 SCIPfreeMemoryArrayNull(scip, &(detectiondata->newpartialdecs));
1189 }
1190
1191 detectiondata->detectiontime = SCIPgetClockTime(scip, temporaryClock);
1192 for( i = 0; i < detectiondata->nnewpartialdecs; ++i )
1193 {
1194 detectiondata->newpartialdecs[i]->addClockTime(detectiondata->detectiontime / detectiondata->nnewpartialdecs);
1195 }
1196
1197 *result = detectordata->result;
1198
1199 SCIP_CALL_ABORT(SCIPfreeClock(scip, &temporaryClock) );
1200
1201 return SCIP_OKAY;
1202}
1203
1204
1205GCG_DECL_PROPAGATEPARTIALDEC(detectorPropagatePartialdecIsomorph)
1206{
1207 *result = SCIP_DIDNOTFIND;
1208 GCG_DETECTORDATA* detectordata = GCGdetectorGetData(detector);
1209 gcg::PARTIALDECOMP* partialdec = partialdecdetectiondata->workonpartialdec ;
1210
1211 partialdecdetectiondata->nnewpartialdecs = 0;
1212 partialdecdetectiondata->newpartialdecs = NULL;
1213
1214 if(partialdec->getNBlocks() != 0 || partialdec->getNOpenvars() != partialdec->getNVars())
1215 {
1216 *result = SCIP_SUCCESS;
1217 return SCIP_OKAY;
1218 }
1219
1220 if( detectordata->maxdecompsextend > 0 )
1221 SCIP_CALL( detectIsomorph(gcg, partialdecdetectiondata, detectordata, result, TRUE, detectordata->maxdecompsextend) );
1222
1223 if( detectordata->maxdecompsexact > 0 )
1224 SCIP_CALL( detectIsomorph(gcg, partialdecdetectiondata, detectordata, result, FALSE, detectordata->maxdecompsexact) );
1225
1226 for( int i = 0; i < partialdecdetectiondata->nnewpartialdecs; ++i )
1227 {
1228 partialdecdetectiondata->newpartialdecs[i]->refineToMaster();
1229 }
1230
1231 return SCIP_OKAY;
1232}
1233#define detectorExitIsomorph NULL
1234
1235#define detectorFinishPartialdecIsomorph NULL
1236
1237#define detectorPostprocessPartialdecIsomorph NULL
1238
1239static
1240GCG_DECL_SETPARAMAGGRESSIVE(setParamAggressiveIsomorph)
1241{
1242 char setstr[SCIP_MAXSTRLEN];
1243 const char* name = GCGdetectorGetName(detector);
1244 int newval;
1245 SCIP_Real modifier;
1247
1248 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
1249 SCIP_CALL( SCIPsetBoolParam(scip, setstr, TRUE) );
1250
1251 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
1252 SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE ) );
1253
1254 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxcallround", name);
1255 SCIP_CALL( SCIPgetIntParam(scip, setstr, &newval) );
1256 ++newval;
1257 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1258 SCIPinfoMessage(scip, NULL, "After Setting %s = %d\n", setstr, newval);
1259
1260
1261 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origmaxcallround", name);
1262 SCIP_CALL( SCIPgetIntParam(scip, setstr, &newval) );
1263 ++newval;
1264 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1265 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1266
1267 /* check if no problem is read */
1269 {
1270 newval = MAX( 0, DEFAULT_MAXDECOMPSEXACT );
1271 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsexact", name);
1272 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1273 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1274
1275 newval = MAX( 0, DEFAULT_MAXDECOMPSEXTEND );
1276 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsextend", name);
1277 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1278 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1279 return SCIP_OKAY;
1280 }
1281
1283
1284 modifier = log(modifier) / log(2);
1285
1286 if (!SCIPisFeasPositive(scip, modifier) )
1287 modifier = -1.;
1288
1289 modifier = SCIPfloor(scip, modifier);
1290 modifier += 0;
1291
1292 newval = MAX( 0, DEFAULT_MAXDECOMPSEXACT - modifier );
1293 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsexact", name);
1294 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1295 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1296
1297 newval = MAX( 0, DEFAULT_MAXDECOMPSEXTEND - modifier );
1298 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsextend", name);
1299 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1300 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1301
1302 return SCIP_OKAY;
1303}
1304
1305
1306static
1307GCG_DECL_SETPARAMDEFAULT(setParamDefaultIsomorph)
1308{
1309 char setstr[SCIP_MAXSTRLEN];
1310 int newval;
1311 SCIP_Real modifier;
1312 const char* name = GCGdetectorGetName(detector);
1314
1315 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
1317
1318 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
1320
1321
1322 /* check if no problem is read */
1324 {
1325 newval = MAX( 0, DEFAULT_MAXDECOMPSEXACT );
1326 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsexact", name);
1327 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1328 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1329
1330 newval = MAX( 0, DEFAULT_MAXDECOMPSEXTEND );
1331 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsextend", name);
1332 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1333 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1334 return SCIP_OKAY;
1335 }
1336
1337
1339
1340 modifier = log(modifier) / log(2);
1341
1342 if (!SCIPisFeasPositive(scip, modifier) )
1343 modifier = -1.;
1344
1345 modifier = SCIPfloor(scip, modifier);
1346 modifier += 2;
1347
1348 newval = MAX( 0, DEFAULT_MAXDECOMPSEXACT - modifier );
1349 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsexact", name);
1350 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1351 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1352
1353 newval = MAX( 0, DEFAULT_MAXDECOMPSEXTEND - modifier );
1354 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsextend", name);
1355 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1356 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1357
1358 return SCIP_OKAY;
1359}
1360
1361static
1362GCG_DECL_SETPARAMFAST(setParamFastIsomorph)
1363{
1364 char setstr[SCIP_MAXSTRLEN];
1365 int newval;
1366 const char* name = GCGdetectorGetName(detector);
1368
1369 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
1370 SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE) );
1371
1372 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
1373 SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE ) );
1374
1375 /* check if no problem is read */
1377 {
1378 newval = MAX( 0, DEFAULT_MAXDECOMPSEXACT );
1379 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsexact", name);
1380 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1381 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1382
1383 newval = MAX( 0, DEFAULT_MAXDECOMPSEXTEND );
1384 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsextend", name);
1385 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1386 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1387 return SCIP_OKAY;
1388 }
1389
1390
1391
1393 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsexact", name);
1394 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1395 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1396
1397 newval = 0;
1398 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxdecompsextend", name);
1399 SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
1400 SCIPinfoMessage(scip, NULL, "%s = %d\n", setstr, newval);
1401
1402 return SCIP_OKAY;
1403
1404}
1405
1406
1407/*
1408 * detector specific interface methods
1409 */
1410
1411
1412/** creates the handler for isomorph subproblems and includes it in SCIP */
1413extern "C"
1415 GCG* gcg /**< GCG data structure */
1416 )
1417{
1418 GCG_DETECTORDATA* detectordata;
1420 detectordata = NULL;
1421
1422 SCIP_CALL( SCIPallocMemory(scip, &detectordata) );
1423 assert(detectordata != NULL);
1424
1425
1426
1428 detectordata, detectorFreeIsomorph, detectorInitIsomorph, detectorExitIsomorph, detectorPropagatePartialdecIsomorph, detectorFinishPartialdecIsomorph, detectorPostprocessPartialdecIsomorph, setParamAggressiveIsomorph, setParamDefaultIsomorph, setParamFastIsomorph) );
1429
1430 /* add isomorph constraint handler parameters */
1431 SCIP_CALL( SCIPaddIntParam(scip, "detection/detectors/isomorph/maxdecompsexact",
1432 "Maximum number of solutions/decompositions with exact detection", &detectordata->maxdecompsexact, FALSE,
1433 DEFAULT_MAXDECOMPSEXACT, 0, INT_MAX, NULL, NULL) );
1434
1435 SCIP_CALL( SCIPaddIntParam(scip, "detection/detectors/isomorph/maxdecompsextend",
1436 "Maximum number of solutions/decompositions with extended detection", &detectordata->maxdecompsextend, FALSE,
1437 DEFAULT_MAXDECOMPSEXTEND, 0, INT_MAX, NULL, NULL) );
1438
1439 return SCIP_OKAY;
1440}
SCIP_VAR * a
SCIP_VAR ** b
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
GCG_EXPORT std::vector< SCIP_Real > & getValsForCons(int consIndex)
returns the nonzero coefficients of the coefficient matrix for a constraint
GCG_EXPORT int getNConss()
returns the number of variables considered in the detprobdata
GCG_EXPORT int getNVarsForCons(int consIndex)
returns the number of variables for a given constraint
GCG_EXPORT SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
GCG_EXPORT std::vector< int > & getVarsForCons(int consIndex)
returns the variable indices of the coefficient matrix for a constraint
GCG_EXPORT SCIP_CONS * getCons(int consIndex)
returns the SCIP constraint related to a constraint index
GCG_EXPORT SCIP_Bool isAssignedToOrigProb()
returns true if the matrix structure corresponds to the presolved problem
class to manage partial decompositions
GCG_EXPORT int getNOpenvars()
Gets size of vector containing variables not assigned yet.
GCG_EXPORT int getNOpenconss()
Gets size of vector containing constraints not assigned yet.
GCG_EXPORT int getNVars()
Gets number of vars.
GCG_EXPORT SCIP_RETCODE isEqual(PARTIALDECOMP *otherpartialdec, SCIP_Bool *isequal, bool sortpartialdecs)
method to check whether this partialdec is equal to a given other partialdec (
GCG_EXPORT void addClockTime(SCIP_Real clocktime)
adds detection time of one detector
GCG_EXPORT std::vector< int > & getOpenconss()
Gets vector containing constraints not assigned yet.
GCG_EXPORT int getNBlocks()
Gets the number of blocks.
void GCGconshdlrDecompAddCandidatesNBlocks(GCG *gcg, SCIP_Bool origprob, int candidate)
adds a candidate for block number and counts how often a candidate is added
const char * GCGdetectorGetName(GCG_DETECTOR *detector)
returns the name of the provided detector
GCG_DETECTORDATA * GCGdetectorGetData(GCG_DETECTOR *detector)
returns the data of the provided detector
SCIP_RETCODE GCGincludeDetector(GCG *gcg, const char *name, const char decchar, const char *description, int freqCallRound, int maxCallRound, int minCallRound, int freqCallRoundOriginal, int maxCallRoundOriginal, int minCallRoundOriginal, int priority, SCIP_Bool enabled, SCIP_Bool enabledFinishing, SCIP_Bool enabledPostprocessing, SCIP_Bool skip, SCIP_Bool usefulRecall, GCG_DETECTORDATA *detectordata, GCG_DECL_FREEDETECTOR((*freeDetector)), GCG_DECL_INITDETECTOR((*initDetector)), GCG_DECL_EXITDETECTOR((*exitDetector)), GCG_DECL_PROPAGATEPARTIALDEC((*propagatePartialdecDetector)), GCG_DECL_FINISHPARTIALDEC((*finishPartialdecDetector)), GCG_DECL_POSTPROCESSPARTIALDEC((*postprocessPartialdecDetector)), GCG_DECL_SETPARAMAGGRESSIVE((*setParamAggressiveDetector)), GCG_DECL_SETPARAMDEFAULT((*setParamDefaultDetector)),)
constraint handler for structure detection
#define detectorFinishPartialdecIsomorph
#define detectorPostprocessPartialdecIsomorph
int renumberPermutations(int *permutation, int permsize)
static GCG_DECL_INITDETECTOR(detectorInitIsomorph)
#define DEC_MAXCALLROUND
static void fhookForPartialdecs(void *user_param, unsigned int N, const unsigned int *aut)
#define DEC_MINCALLROUNDORIGINAL
#define DEC_ENABLEDFINISHING
#define DEC_ENABLED
static std::vector< std::vector< int > > getAllSubsets(std::vector< int > set)
#define SET_MULTIPLEFORSIZETRANSF
#define DEFAULT_MAXDECOMPSEXACT
#define DEFAULT_MAXDECOMPSEXTEND
static GCG_DECL_FREEDETECTOR(detectorFreeIsomorph)
static GCG_DECL_SETPARAMAGGRESSIVE(setParamAggressiveIsomorph)
#define DEC_DECCHAR
SCIP_RETCODE GCGincludeDetectorIsomorphism(GCG *gcg)
#define DEC_NAME
#define DEC_MINCALLROUND
static SCIP_RETCODE createGraph(SCIP *scip, AUT_COLOR colorinfo, AUT_GRAPH *graph, SCIP_RESULT *result, gcg::PARTIALDECOMP *partialdec, gcg::DETPROBDATA *detprobdata)
#define DEC_ENABLEDPOSTPROCESSING
static SCIP_RETCODE setupArrays(SCIP *scip, AUT_COLOR *colorinfo, SCIP_RESULT *result, gcg::PARTIALDECOMP *partialdec, gcg::DETPROBDATA *detprobdata)
SCIP_RETCODE reorderPermutations(GCG *gcg, gcg::DETPROBDATA *detprobdata, int *permutation, int permsize, int nperms)
static void freeMemory(SCIP *scip, AUT_COLOR *colorinfo)
SCIP_RETCODE createPartialdecFromMasterconss(SCIP *scip, gcg::PARTIALDECOMP **newPartialdec, int *masterconss, int nmasterconss, gcg::PARTIALDECOMP *partialdec, gcg::DETPROBDATA *detprobdata, SCIP_Bool exact)
static GCG_DECL_SETPARAMFAST(setParamFastIsomorph)
#define DEC_DESC
#define DEC_FREQCALLROUND
void collapsePermutation(int *permutation, int permsize)
GCG_DECL_PROPAGATEPARTIALDEC(detectorPropagatePartialdecIsomorph)
#define DEC_PRIORITY
static SCIP_RETCODE detectIsomorph(GCG *gcg, PARTIALDEC_DETECTION_DATA *detectiondata, GCG_DETECTORDATA *detectordata, SCIP_RESULT *result, SCIP_Bool onlysign, int maxdecomps)
static GCG_DECL_SETPARAMDEFAULT(setParamDefaultIsomorph)
#define DEC_USEFULRECALL
#define DEC_SKIP
#define DEC_MAXCALLROUNDORIGINAL
#define detectorExitIsomorph
#define DEC_FREQCALLROUNDORIGINAL
struct struct_hook AUT_HOOK
static SCIP_RETCODE allocMemory(SCIP *scip, AUT_COLOR *colorinfo, int nconss, int nvars)
static int gcd(int a, int b)
detector for pricing problems that can be aggregated (uses bliss)
#define SCIP_MAXSTRLEN
#define SCIP_Bool
#define MIN(x, y)
#define SCIP_Real
#define MAX(x, y)
#define SCIP_CALL_ABORT(x)
#define SCIP_CALL(x)
#define TRUE
#define FALSE
#define nnodes
GCG interface methods.
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
SCIP_STAGE SCIPgetStage(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIP_RETCODE SCIPgetIntParam(SCIP *scip, const char *name, int *value)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
const char * SCIPconsGetName(SCIP_CONS *cons)
#define SCIPfreeMemoryArrayNull(scip, ptr)
#define SCIPreallocMemoryArray(scip, ptr, newnum)
#define SCIPallocMemoryArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPfreeMemoryArray(scip, ptr)
#define SCIPfreeMemory(scip, ptr)
SCIP_RETCODE SCIPcreateClock(SCIP *scip, SCIP_CLOCK **clck)
SCIP_RETCODE SCIPstopClock(SCIP *scip, SCIP_CLOCK *clck)
SCIP_RETCODE SCIPfreeClock(SCIP *scip, SCIP_CLOCK **clck)
SCIP_Real SCIPgetClockTime(SCIP *scip, SCIP_CLOCK *clck)
SCIP_RETCODE SCIPstartClock(SCIP *scip, SCIP_CLOCK *clck)
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
int SCIPvarGetProbindex(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
void SCIPsortDownIntInt(int *intarray1, int *intarray2, int len)
int SCIPsnprintf(char *t, int len, const char *s,...)
#define NULL
#define BMSclearMemoryArray(ptr, num)
struct gcg::subset subset
helper functions for automorphism detection
struct struct_cons AUT_CONS
struct struct_colorinformation AUT_COLOR
struct struct_graph AUT_GRAPH
struct struct_coef AUT_COEF
struct struct_var AUT_VAR
public methods for working with decomposition structures
public methods for GCG variables
#define SCIPdebugMessage
#define SCIPdebugPrintf
various SCIP helper methods
SCIP_RESULT result
Definition: dec_dbscan.cpp:91
Definition: struct_gcg.h:55
interface data structure for the detector calling methods
gcg::PARTIALDECOMP ** newpartialdecs
gcg::PARTIALDECOMP * workonpartialdec
gcg::DETPROBDATA * detprobdata
int size
struct_hook(SCIP_Bool aut, unsigned int n, SCIP *scip)
gcg::PARTIALDECOMP * getPartialdec()
gcg::PARTIALDECOMP * partialdec
SCIP_Bool aut
gcg::DETPROBDATA * getDetprobdata()
SCIP_Bool getBool()
unsigned int n
void setBool(SCIP_Bool aut)
SCIP * getScip()
gcg::DETPROBDATA * detprobdata
SCIP_VERBLEVEL_NORMAL
SCIP_DIDNOTFIND
SCIP_SUCCESS
enum SCIP_Result SCIP_RESULT
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE
SCIP_STAGE_PROBLEM
SCIP_STAGE_TRANSFORMED