Scippy

GCG

Branch-and-Price & Column Generation for Everyone

cons_decomp.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 cons_decomp.cpp
30 *
31 * @brief constraint handler for structure detection
32 * @author Martin Bergner
33 * @author Christian Puchert
34 * @author Michael Bastubbe
35 * @author Hanna Franzen
36 * @author William Ma
37 * @author Erik Muehmer
38 *
39 * This constraint handler will run all registered structure detectors in a loop. They will find partial decompositions in a loop iteration until the decompositions are full
40 * or the maximum number of detection rounds is reached.
41 *
42 */
43
44/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
45
46//#define SCIP_DEBUG
47
48#include <cassert>
49#include <cstddef>
50#include <cstdio>
51#include <cstring>
52#include <algorithm>
53#include <deque>
54#include <iomanip>
55#include <sstream>
56#include <utility>
57#include <regex>
58#include <vector>
59#include <list>
60
61#include <scip/clock.h>
62#include <scip/pub_cons.h>
63#include <scip/pub_misc.h>
64#include <scip/type_paramset.h>
65#include <scip/scipdefplugins.h>
66
70#include "gcg/scip_misc.h"
71#include "gcg/relax_gcg.h"
72#include "gcg/decomp.h"
73#include "gcg/cons_decomp.hpp"
74#include "gcg/cons_decomp.h"
77#include "gcg/struct_decomp.h"
78#include "gcg/struct_score.h"
79
80/* constraint handler properties */
81#define CONSHDLR_NAME "decomp" /**< name of constraint handler */
82#define CONSHDLR_DESC "constraint handler for structure detection" /**< description of constraint handler */
83#define CONSHDLR_ENFOPRIORITY 0 /**< priority of the constraint handler for constraint enforcing */
84#define CONSHDLR_CHECKPRIORITY 0 /**< priority of the constraint handler for checking feasibility */
85#define CONSHDLR_EAGERFREQ -1 /**< frequency for using all instead of only the useful constraints in separation,
86 * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
87#define CONSHDLR_NEEDSCONS FALSE /**< should the constraint handler be skipped, if no constraints are available? */
88
89#define DEFAULT_ENABLED TRUE /**< indicates whether detection is enabled */
90
91#define DEFAULT_BLOCKNUMBERCANDSMEDIANVARSPERCONS FALSE /**< should for block number candidates calculation the medianvarspercons calculation be considered */
92
93#define DEFAULT_MAXDETECTIONROUNDS 1 /**< maximal number of detection rounds */
94#define DEFAULT_MAXDETECTIONTIME 600 /**< maximum detection time in seconds */
95#define DEFAULT_POSTPROCESS TRUE /**< indicates whether to postprocess full decompositions */
96#define DEFAULT_MAXNCLASSESLARGEPROBS 5 /**< maximum number of classes allowed for large (nvars+nconss > 50000) MIPs for detectors, partitions with more classes are reduced to the maximum number of classes */
97#define DEFAULT_MAXNCLASSES 9 /**< maximum number of classes allowed for detectors, partitions with more classes are reduced to the maximum number of classes */
98#define DEFAULT_MAXNCLASSESFORNBLOCKCANDIDATES 18 /**< maximum number of classes a partition can have to be used for voting nblockcandidates */
99#define DEFAULT_ENABLEORIGDETECTION TRUE /**< indicates whether to start detection for the original problem */
100
101/* classifier */
102
103#define DEFAULT_ALLOWPARTITIONDUPLICATES FALSE /**< if false each new (conss- and vars-) partitions is checked for being a duplicate of an existing one, if so it is not added and NBOT statistically recognized*/
104#define DEFAULT_CLASSIFY TRUE /**< indicates whether classification is enabled */
105#define DEFAULT_ENABLEORIGCLASSIFICATION TRUE /**< indicates whether to start detection for the original problem */
106
107#define DEFAULT_BENDERSONLYCONTSUBPR FALSE /**< indicates whether only decomposition with only continuous variables in the subproblems should be searched*/
108#define DEFAULT_BENDERSONLYBINMASTER FALSE /**< indicates whether only decomposition with only binary variables in the master should be searched */
109
110#define DEFAULT_LEVENSHTEIN_MAXMATRIXHALFPERIMETER 10000 /**< deactivate levenshtein constraint classifier if nrows + ncols exceeds this value for emphasis default */
111#define AGGRESSIVE_LEVENSHTEIN_MAXMATRIXHALFPERIMETER 80000 /**< deactivate levenshtein constraint classifier if nrows + ncols exceeds this value for emphasis aggressive */
112#define FAST_LEVENSHTEIN_MAXMATRIXHALFPERIMETER 2000 /**< deactivate levenshtein constraint classifier if nrows + ncols exceeds this value for emphasis fast */
113
114#define DEFAULT_DETECTBENDERS FALSE /**< indicates whether benders detection mode is enabled */
115
116#define DEFAULT_SCORE "spfwh" /**< score shortname that is activated */
117
118/*
119 * Data structures
120 */
121
122/** constraint handler data */
124{
125 GCG* gcg; /**< the GCG instance */
126 SCIP_Bool enabled; /**< indicates whether detection is enabled */
127
128 std::vector<PARTIALDECOMP*>* partialdecs; /**< list of all existing partialdecs */
129 std::unordered_map<int, PARTIALDECOMP*>* partialdecsbyid; /**< list of all existing partialdecs */
130 int partialdeccounter; /**< counts the number of created partialdecs, used to determine next partialdec id
131 (NOT amount of currently existing partialdecs as partialdecs might be deleted) */
132 GCG_DECOMP** decomps; /**< array of decomposition structures */
133 int ndecomps; /**< number of decomposition structures (size of decomps)*/
134
135 GCG_CONSCLASSIFIER** consclassifiers; /**< array of cons classifiers */
136 int nconsclassifiers; /**< number of cons classifiers */
137 int* consclassifierpriorities; /**< priorities of the cons classifiers */
138 GCG_VARCLASSIFIER** varclassifiers; /**< array of var classifiers */
139 int nvarclassifiers; /**< number of var classifiers */
140 int* varclassifierpriorities; /**< priorities of the var classifiers */
141
142 GCG_DETECTOR** detectors; /**< array of structure detectors */
143 int* priorities; /**< priorities of the detectors */
144 int ndetectors; /**< number of detectors */
145 GCG_DETECTOR** propagatingdetectors; /**< array of detectors able to propagate partial decompositions */
146 int npropagatingdetectors; /**< number of detectors able to propagate partial decompositions (size of propagatingdetectors) */
147 GCG_DETECTOR** finishingdetectors; /**< array of detectors able to finish partial decompositions */
148 int nfinishingdetectors; /**< number of detectors able to finish partial decompositions (size of finishingdetectors) */
149 GCG_DETECTOR** postprocessingdetectors; /**< array of detectors able to postprocess decompositions */
150 int npostprocessingdetectors; /**< number of detectors able to postprocess decompositions (size of postprocessingdetectors) */
151
152 SCIP_CLOCK* detectorclock; /**< clock to measure detection time */
153 SCIP_CLOCK* completedetectionclock; /**< clock to measure detection time */
154 SCIP_Bool hasrunoriginal; /**< flag to indicate whether we have already detected (original problem) */
155 SCIP_Bool hasrun; /**< flag to indicate whether we have already detected */
156 int maxndetectionrounds; /**< maximum number of detection loop rounds */
157 int maxdetectiontime; /**< maximum detection time [sec] */
158 SCIP_Bool postprocess; /**< indicates whether to postprocess full decompositions */
159 SCIP_Bool blocknumbercandsmedianvarspercons; /**< should for block number candidates calculation the medianvarspercons calculation be considered */
160 int maxnclassesfornblockcandidates; /**< maximum number of classes a partition can have to be used for voting nblockcandidates */
161 int maxnclassesperpartition; /**< maximum number of classes allowed for detectors, partition with more classes are reduced to the maximum number of classes */
162 int maxnclassesperpartitionforlargeprobs; /**< maximum number of classes allowed for large (nvars+nconss > 50000) MIPs for detectors, partition with more classes are reduced to the maximum number of classes */
163 int weightinggpresolvedoriginaldecomps; /**< weighing method for comparing presolved and original decompositions (see corresponding enum) */
164
165 SCIP_Bool classify; /**< indicates whether classification should take place */
166 SCIP_Bool allowpartitionduplicates; /**< indicates whether partition duplicates are allowed (for statistical reasons) */
167 SCIP_Bool enableorigdetection; /**< indicates whether to start detection for the original problem */
168 SCIP_Bool enableorigclassification; /**< indicates whether to start constraint classification for the original problem */
169
170 SCIP_Bool bendersonlycontsubpr; /**< indicates whether only decomposition with only continuous variables in the subproblems should be searched*/
171 SCIP_Bool bendersonlybinmaster; /**< indicates whether only decomposition with only binary variables in the master should be searched */
172 SCIP_Bool detectbenders; /**< indicates wethher or not benders detection mode is enabled */
173
174 int ncallscreatedecomp; /**< debugging method for counting the number of calls of created decompositions */
175
176 gcg::DETPROBDATA* detprobdatapres; /**< detprobdata containing data for the presolved transformed problem */
177 gcg::DETPROBDATA* detprobdataorig; /**< detprobdata containing data for the original problem */
178
179 /* score data */
180 GCG_SCORE** scores; /**< array of scores */
181 int nscores; /**< number of scores */
182 char* currscore; /**< currently chosen score shortname */
183 SCIP_CLOCK* scoreclock; /**< clock tracking the total score calculation time */
184
185 PARTIALDECOMP* partialdectowrite; /**< pointer enabling the use of SCIPs writeProb/writeTransProb function for writing partial decompositions*/
186
187 SCIP_Bool consnamesalreadyrepaired; /**< stores whether or not */
188 std::vector<int>* userblocknrcandidates; /**< vector to store block number candidates that were given by user */
189 SCIP_Bool freeorig; /**< help bool to notify a nonfinal free transform (needed if presolving is revoked, e.g. if orig decomposition is used, and transformation is not successful) */
190};
191
192
193/** parameter how to modify scores when comparing decompositions for original and presolved problem
194 * (which might differ in size) */
196 NO_MODIF = 0, /**< no modification */
197 FRACTION_OF_NNONZEROS, /**< scores are weighted according to ratio of number nonzeros, the more the worse */
198 FRACTION_OF_NROWS, /**< scores are weighted according to ratio of number rows, the more the worse */
199 FAVOUR_PRESOLVED /**< decompositions for presolved problems are always favoured over decompositions of original problem */
201
202
203/** locally used macro to help with sorting, comparator */
204struct sort_pred {
205 bool operator()(const std::pair<PARTIALDECOMP*, SCIP_Real> &left, const std::pair<PARTIALDECOMP*, SCIP_Real> &right) {
206 return left.second > right.second;
207 }
208};
209
210
211//////////////////////////////////////////////////
212//////////////////////////////////////////////////
213//////////////////////////////////////////////////
214
215/*
216 * Local methods
217 */
218
219
220/**
221 * @brief local function to get the conshdlr data of the current conshdlr
222 *
223 * @returns the conshdlrdata iff it exists, else NULL
224 * @note returns NULL iff conshdlr or its data does not exist
225 */
226static
228 GCG* gcg /**< SCIP data structure */
229 )
230{
231 /* get current conshdlr, identified by the name define */
232 assert(gcg != NULL);
234
235 /* check if conshdlr was found */
236 if( conshdlr == NULL )
237 {
238 SCIPerrorMessage("Decomp constraint handler is not included, cannot get its data!\n");
239 return NULL;
240 }
241
242 /* this will result in NULL if none is stored */
243 return SCIPconshdlrGetData(conshdlr);
244}
245
246
247/** @brief local method to handle store a partialdec in the correct detprobdata
248 *
249 * @returns SCIP status */
250static
252 GCG* gcg, /**< GCG data structure */
253 PARTIALDECOMP* partialdec /**< partialdec pointer */
254 )
255{
256 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
257 bool success;
258
259 if( partialdec->isComplete() )
260 {
261 if( partialdec->isAssignedToOrigProb() )
262 success = conshdlrdata->detprobdataorig->addPartialdecToFinished(partialdec);
263 else
264 success = conshdlrdata->detprobdatapres->addPartialdecToFinished(partialdec);
265 }
266 else
267 {
268 if( partialdec->isAssignedToOrigProb() )
269 success = conshdlrdata->detprobdataorig->addPartialdecToOpen(partialdec);
270 else
271 success = conshdlrdata->detprobdatapres->addPartialdecToOpen(partialdec);
272 }
273
274 if( !success )
275 SCIPverbMessage(GCGgetOrigprob(gcg), SCIP_VERBLEVEL_FULL, NULL, "Decomposition to add is already known to gcg!\n");
276
277 return SCIP_OKAY;
278}
279
280
282 GCG* gcg, /**< GCG data structure */
283 int partialdecid /**< partialdec id */
284 )
285{
286 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
287
288 auto itr = conshdlrdata->partialdecsbyid->find(partialdecid);
289 if( itr != conshdlrdata->partialdecsbyid->end() )
290 {
291 return itr->second;
292 }
293
294 return NULL;
295}
296
297
298/** @brief translates a vector of PARTIALDECOMP pointers into an array of their ids
299 * @returns SCIP return code
300 */
301static
303 std::vector<PARTIALDECOMP*>& partialdecs, /**< vector of partialdecs (input) */
304 int** idlist, /**< array of ids (output) */
305 int* listlength /**< length of id array (output) */
306 )
307{
308 *listlength = (int) partialdecs.size();
309 int i;
310 for(i = 0; i < (int) partialdecs.size(); i++)
311 {
312 (*idlist)[i] = partialdecs[i]->getID();
313 }
314
315 return SCIP_OKAY;
316}
317
318
319/** @brief gets all selected partialdecs
320 * @returns vector of all selected partialdecs */
321static
322std::vector<PARTIALDECOMP*> getSelectedPartialdecs(
323 GCG* gcg, /**< GCG data structure */
324 std::vector<PARTIALDECOMP*>& selectedpartialdecs /**< vector of partialdecs (input) */
325 )
326{
327 /* get all partialdecs */
328 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
329
330 /* look for selected ones and add them */
331 for(auto partialdec : *conshdlrdata->partialdecs)
332 {
333 if(partialdec->isSelected())
334 {
335 selectedpartialdecs.push_back(partialdec);
336 }
337 }
338 return selectedpartialdecs;
339}
340
341
342/** @brief gets vector of all finished partialdecs
343 */
344static
346 GCG* gcg, /**< GCG data structure */
347 std::vector<PARTIALDECOMP*>& finishedpartialdecs /**< will contain finished partialdecs */
348 )
349{
350 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
351
352 for(auto partialdec : *conshdlrdata->partialdecs)
353 {
354 if(partialdec->isComplete())
355 finishedpartialdecs.push_back(partialdec);
356 }
357}
358
359
360/**
361 * method to unselect all decompositions, called in consexit, and when the partialdeclist is updated
362 * (especially if new (partial ones) are added )
363 *
364 *@returns SCIP return code
365 */
366static
368 GCG* gcg /**< GCG data structure */
369 )
370{
371 /* get all partialdecs */
372 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
373
374 /* set each partialdec to not selected */
375 for(auto partialdec : *conshdlrdata->partialdecs)
376 {
377 partialdec->setSelected(false);
378 }
379
380 return SCIP_OKAY;
381}
382
383
384/** @brief initializes a new detection data structure
385 *
386 * @returns new detection data structure
387 */
388static
390 gcg::DETPROBDATA *detprobdata, /**< detprobdata to point to */
391 PARTIALDECOMP* partialdec /**< partialdec to pass to detector */
392 )
393{
394 PARTIALDEC_DETECTION_DATA *partialdecdetdata;
395 partialdecdetdata = new PARTIALDEC_DETECTION_DATA();
396 partialdecdetdata->detprobdata = detprobdata;
397 partialdecdetdata->nnewpartialdecs = 0;
398 partialdecdetdata->workonpartialdec = new gcg::PARTIALDECOMP( partialdec );
399 return partialdecdetdata;
400}
401
402
403/**
404 * @brief resets/creates the detprobdata for the given problem
405 * @returns scip return code
406 */
407static
409 GCG* gcg, /**< GCG data structure */
410 SCIP_Bool original /**< whether to do this for the original problem */
411 )
412{
414 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
415 assert(conshdlrdata != NULL);
416
419
420 // for the orig detprobdata, reset only the current partialdecs as the rest will stay the same in any case
421 if(original)
422 {
423 if( conshdlrdata->detprobdataorig == NULL )
424 conshdlrdata->detprobdataorig = new gcg::DETPROBDATA(gcg, original);
426 }
427 // for the presolved problem, the detprobdata is deleted and a new one is created
428 else
429 {
431 if( conshdlrdata->detprobdatapres != NULL )
432 delete conshdlrdata->detprobdatapres;
433 conshdlrdata->detprobdatapres = new gcg::DETPROBDATA(gcg, original);
434 }
435
436 return SCIP_OKAY;
437}
438
439
440/** @brief delets the detection data structure
441 *
442 * frees all relevant data within the construct before deleting the main structure
443 * @returns SCIP return code
444 */
445static
447 SCIP* scip, /**< SCIP data structure */
448 PARTIALDEC_DETECTION_DATA* data /**< data to delete */
449 )
450{
452 delete data->workonpartialdec;
453 data->newpartialdecs = NULL;
454 data->nnewpartialdecs = 0;
455 delete data;
456
457 return SCIP_OKAY;
458}
459
460
461/** @brief constructs partialdecs using the registered detectors
462 *
463 * Takes the current partialdecs in the detprobdata as root,
464 * propagates, finishes and postprocesses in rounds.
465 *
466 * @return user has to free partialdecs */
467static
469 GCG* gcg, /**< GCG data structure */
470 gcg::DETPROBDATA* detprobdata /**< detprobdata for problem the detection should be performed on */
471 )
472{
473 SCIP* origprob = GCGgetOrigprob(gcg);
475 int maxndetectionrounds;
476 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
477
478 SCIP_CALL_ABORT( SCIPgetIntParam( origprob, "detection/maxrounds", &maxndetectionrounds ) );
479
480 // Fill partialdecs vector into deque
481 std::deque<PARTIALDECOMP*> partialdecqueue;
482 for( auto partialdecomp: detprobdata->getOpenPartialdecs() )
483 {
484 partialdecqueue.push_back(partialdecomp);
485 }
486
487 // TODO while not strg-c
488 while (!partialdecqueue.empty() && (
489 conshdlrdata->maxdetectiontime == 0 ||
490 SCIPgetClockTime(origprob, conshdlrdata->detectorclock) < conshdlrdata->maxdetectiontime
491 ))
492 {
493 gcg::PARTIALDECOMP *partialdec = partialdecqueue.front();
494 partialdecqueue.pop_front();
495
496 // Check if max round reached for this partialdec
497 if((int) partialdec->getDetectorchain().size() >= maxndetectionrounds)
498 {
499 continue;
500 }
501
502 // TODO (priority for "promising pairs")
503 for (int j = 0; j < conshdlrdata->npropagatingdetectors; j++)
504 {
505 GCG_DETECTOR* detector;
506 detector = conshdlrdata->propagatingdetectors[j];
507
508 if( !detector->enabled )
509 {
510 continue;
511 }
512
513 /* skip detector if it should not be recalled */
514 if( !detector->usefulRecall && partialdec->isPropagatedBy( detector ) )
515 continue;
516
517 PARTIALDEC_DETECTION_DATA* partialdecdetdata = createPartialdecDetectionData(detprobdata, partialdec);
518
519 // PROPAGATE
520 SCIP_CALL( detector->propagatePartialdec(gcg, detector, partialdecdetdata, &result) );
521 detector->dectime += partialdecdetdata->detectiontime;
522
523 // Handle found Partialdecs
524 for( int k = 0; k < partialdecdetdata->nnewpartialdecs; ++ k )
525 {
526 PARTIALDECOMP* newpartialdec = partialdecdetdata->newpartialdecs[k];
527 newpartialdec->setDetectorPropagated(detector);
528 newpartialdec->prepare();
529 newpartialdec->addDecChangesFromAncestor(partialdec);
530
531 // If is already complete => store for POSTPROCESSING
532 if( newpartialdec->isComplete() )
533 {
534 if( !detprobdata->addPartialdecToFinished(newpartialdec) )
535 {
536 delete newpartialdec;
537 newpartialdec = NULL;
538 }
539 }
540 else
541 {
542 // Store for further PROPAGATION
543 if( detprobdata->addPartialdecToOpen(newpartialdec) )
544 partialdecqueue.push_back(newpartialdec);
545 else
546 {
547 delete newpartialdec;
548 newpartialdec = NULL;
549 }
550 }
551 if( newpartialdec != NULL )
552 detprobdata->addPartialdecToAncestor(newpartialdec);
553 }
554 deletePartialdecDetectionData(origprob, partialdecdetdata);
555 }
556 detprobdata->addPartialdecToAncestor(partialdec);
557 }
558
559 // FINISH partialdecs
560 for( auto partialdecomp: detprobdata->getOpenPartialdecs() )
561 {
562 for(int l = 0; l < conshdlrdata->nfinishingdetectors; l++)
563 {
564 GCG_DETECTOR *finishingdetector = conshdlrdata->finishingdetectors[l];
565 if( !finishingdetector->enabledFinishing )
566 {
567 continue;
568 }
569
570 PARTIALDEC_DETECTION_DATA *finishingdata = createPartialdecDetectionData(detprobdata, partialdecomp);
571 SCIP_CALL( finishingdetector->finishPartialdec(gcg, finishingdetector, finishingdata, &result) );
572 finishingdetector->dectime += finishingdata->detectiontime;
573
574 for(int finished = 0; finished < finishingdata->nnewpartialdecs; ++finished)
575 {
576 PARTIALDECOMP* newpartialdec = finishingdata->newpartialdecs[finished];
577 newpartialdec->deleteEmptyBlocks(false);
578 newpartialdec->setDetectorFinished(finishingdetector);
579
580 newpartialdec->prepare();
581 newpartialdec->addDecChangesFromAncestor(partialdecomp);
582 if( !detprobdata->addPartialdecToFinished(newpartialdec) )
583 delete newpartialdec;
584 }
585 deletePartialdecDetectionData(origprob, finishingdata);
586 }
587 }
588
589 // POSTPROCESSING of finished partialdecs
590 if(conshdlrdata->postprocess)
591 {
592 SCIP_CLOCK* postprocessingclock;
593 SCIPcreateClock( origprob, & postprocessingclock );
594 SCIP_CALL_ABORT( SCIPstartClock( origprob, postprocessingclock ) );
595 auto& finishedpartialdecs = detprobdata->getFinishedPartialdecs();
596 int numpostprocessed = 0;
597 int nfinished = (int) finishedpartialdecs.size();
598 for( int i = 0; i < nfinished; ++i )
599 {
600 auto postpartialdec = finishedpartialdecs[i];
601
602 // Check if postprocessing is enabled globally
603 for( int d = 0; d < conshdlrdata->npostprocessingdetectors; ++d )
604 {
605 GCG_DETECTOR* postdetector = conshdlrdata->postprocessingdetectors[d];
606 /* if the postprocessing of the detector is not enabled go on with the next detector */
607 if( !postdetector->enabledPostprocessing )
608 {
609 continue;
610 }
611
612 PARTIALDEC_DETECTION_DATA* partialdecdetdata = createPartialdecDetectionData(detprobdata, postpartialdec);
613
614 SCIPverbMessage(origprob, SCIP_VERBLEVEL_FULL, NULL, "call finisher for detector %s \n", GCGdetectorGetName( postdetector ) );
615
616 // POSTPROCESS
617 SCIP_CALL( postdetector->postprocessPartialdec(gcg, postdetector, partialdecdetdata, &result ) );
618 postdetector->dectime += partialdecdetdata->detectiontime;
619
620 for( int finished = 0; finished < partialdecdetdata->nnewpartialdecs; ++finished )
621 {
622 PARTIALDECOMP* newpartialdec = partialdecdetdata->newpartialdecs[finished];
623
624 newpartialdec->setDetectorPropagated(postdetector);
625 newpartialdec->setFinishedByFinisher(true );
626 newpartialdec->prepare();
627 newpartialdec->addDecChangesFromAncestor(postpartialdec);
628
629 if( !detprobdata->addPartialdecToFinished(newpartialdec) )
630 delete newpartialdec;
631 else
632 numpostprocessed += 1;
633
634 }
635 deletePartialdecDetectionData(origprob, partialdecdetdata);
636 }
637 }
638
639 SCIP_CALL_ABORT( SCIPstopClock( origprob, postprocessingclock ) );
640
641 detprobdata->postprocessingtime += SCIPgetClockTime( origprob, postprocessingclock );
642 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, "POSTPROCESSING of decompositions. Added %d new decomps. \n", numpostprocessed);
643 SCIP_CALL_ABORT( SCIPfreeClock( origprob, & postprocessingclock ) );
644 }
645 else
646 {
647 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, "POSTPROCESSING disabled\n");
648 } // end for postprocessing finished partialdecs
649
650 // STATS
651 // count the successful refinement calls for each detector
652
653 // finished partialdecs
654 for( PARTIALDECOMP* partialdec: detprobdata->getFinishedPartialdecs() )
655 {
656 assert( partialdec->checkConsistency() );
657 assert( partialdec->getNOpenconss() == 0 );
658 assert( partialdec->getNOpenvars() == 0 );
659
660 for( int d = 0; d < conshdlrdata->ndetectors; ++ d )
661 {
662 if( partialdec->isPropagatedBy(conshdlrdata->detectors[d]) )
663 {
664 conshdlrdata->detectors[d]->ndecomps += 1;
665 conshdlrdata->detectors[d]->ncompletedecomps += 1;
666 }
667 }
668 }
669
670 // open partialdecs
671 for( PARTIALDECOMP* partialdec: detprobdata->getOpenPartialdecs() )
672 {
673 assert( partialdec->checkConsistency() );
674
675 for( int d = 0; d < conshdlrdata->ndetectors; ++ d )
676 {
677 if( partialdec->isPropagatedBy(conshdlrdata->detectors[d]) )
678 conshdlrdata->detectors[d]->ndecomps += 1;
679 }
680 }
681
682 /* preliminary output detector stats */
683 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, "Found %d finished decompositions.\n",
684 detprobdata->getNFinishedPartialdecs());
685 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, "Measured running time per detector:\n");
686
687 for( int i = 0; i < conshdlrdata->ndetectors; ++ i )
688 {
689 if( conshdlrdata->detectors[i]->ncompletedecomps > 0 )
690 {
692 "Detector %-25.25s worked on %8d finished decompositions and took a total time of %10.3f\n",
693 GCGdetectorGetName( conshdlrdata->detectors[i]), conshdlrdata->detectors[i]->ncompletedecomps,
694 conshdlrdata->detectors[i]->dectime);
695 }
696 }
697
698 return SCIP_OKAY;
699}
700
701
702/** @brief initialization method of constraint handler (called after problem was transformed) */
703static
704SCIP_DECL_CONSINIT(consInitDecomp)
705{ /*lint --e{715}*/
706 SCIP_CONSHDLRDATA* conshdlrdata;
707 int i;
708 conshdlrdata = SCIPconshdlrGetData(conshdlr);
709 assert(conshdlrdata != NULL);
710
711 /* the detection hast not run yet */
712 conshdlrdata->hasrun = FALSE;
713 conshdlrdata->hasrunoriginal = FALSE;
714
715 for( i = 0; i < conshdlrdata->ndetectors; ++i )
716 {
717 GCG_DETECTOR *detector;
718 detector = conshdlrdata->detectors[i];
719 assert(detector != NULL);
720
721 /* add the detector time of each detector to 0 */
722 detector->dectime = 0.;
723 /* init the detectors */
724 if( detector->initDetector != NULL )
725 {
726 SCIPdebugMessage("Calling initDetector of %s\n", detector->name);
727 SCIP_CALL( (*detector->initDetector)(conshdlrdata->gcg, detector) );
728 }
729 }
730
731 return SCIP_OKAY;
732}
733
734
735/** @brief deinitialization method of constraint handler (called before transformed problem is freed) */
736static
737SCIP_DECL_CONSEXIT(consExitDecomp)
738{ /*lint --e{715}*/
739 SCIP_CONSHDLRDATA* conshdlrdata;
740 int i;
741
742 assert(conshdlr != NULL);
743 assert(scip != NULL);
744
745 conshdlrdata = SCIPconshdlrGetData(conshdlr);
746 assert(conshdlrdata != NULL);
747
748 /* remove all decomps */
749 if( conshdlrdata->ndecomps > 0 && conshdlrdata->decomps != NULL )
750 {
751 for( int dec = 0; dec < conshdlrdata->ndecomps; ++dec )
752 {
753 GCGdecompFree(conshdlrdata->gcg, &conshdlrdata->decomps[conshdlrdata->ndecomps - dec - 1]);
754 }
755
756 /* remove decomp array structure */
757 SCIPfreeBlockMemoryArray(scip, &conshdlrdata->decomps, conshdlrdata->ndecomps);
758 conshdlrdata->ndecomps = 0;
759 conshdlrdata->decomps = NULL;
760 }
761
762 /* reset the run */
763 conshdlrdata->hasrun = FALSE;
764
765 /* release the detectors' data sets */
766 for( i = 0; i < conshdlrdata->ndetectors; ++i )
767 {
768 GCG_DETECTOR *detector;
769 detector = conshdlrdata->detectors[i];
770 assert(detector != NULL);
771
772 if( detector->exitDetector != NULL )
773 {
774 SCIPdebugMessage("Calling exitDetector of %s\n", detector->name);
775 SCIP_CALL( (*detector->exitDetector)(conshdlrdata->gcg, detector) );
776 }
777 }
778
780
781 /* remove selection of partialdecs */
782 unselectAllPartialdecs(conshdlrdata->gcg);
783
784 return SCIP_OKAY;
785}
786
787
788/** @brief destructor of constraint handler to free constraint handler data (called when SCIP is exiting) */
789static
790SCIP_DECL_CONSFREE(consFreeDecomp)
791{
792 SCIP_CONSHDLRDATA* conshdlrdata;
793 int i;
794 conshdlrdata = SCIPconshdlrGetData(conshdlr);
795 assert(conshdlrdata != NULL);
796
797 /* free detection time clocks */
798 SCIP_CALL( SCIPfreeClock(scip, &conshdlrdata->detectorclock) );
800
801 /* free all detectors */
802 for( i = 0; i < conshdlrdata->ndetectors; ++i )
803 {
804 GCG_DETECTOR *detector;
805 detector = conshdlrdata->detectors[i];
806 assert(detector != NULL);
807
808 if( detector->freeDetector != NULL )
809 {
810 SCIPdebugMessage("Calling freeDetector of %s\n", detector->name);
811 SCIP_CALL( (*detector->freeDetector)(conshdlrdata->gcg, detector) );
812 }
813
814 BMSfreeMemoryArray(&detector->name);
816
817 SCIPfreeBlockMemory(scip, &detector);
818 }
819
820 /* free all consclassifiers */
821 for( i = 0; i < conshdlrdata->nconsclassifiers; ++i )
822 {
823 GCG_CONSCLASSIFIER *consclassifier = conshdlrdata->consclassifiers[i];
824 assert(consclassifier != NULL);
825
826 if( consclassifier->freeClassifier != NULL )
827 {
828 SCIPdebugMessage("Calling freeClassifier of consclassifier %s\n", consclassifier->name);
829 SCIP_CALL( (*consclassifier->freeClassifier)(conshdlrdata->gcg, consclassifier) );
830 }
831
832 BMSfreeMemoryArray(&consclassifier->name);
833 BMSfreeMemoryArray(&consclassifier->description);
834
835 SCIPfreeBlockMemory(scip, &conshdlrdata->consclassifiers[i]);
836 }
837
838 /* free all varclassifiers */
839 for( i = 0; i < conshdlrdata->nvarclassifiers; ++i )
840 {
841 GCG_VARCLASSIFIER *varclassifier = conshdlrdata->varclassifiers[i];
842 assert(varclassifier != NULL);
843
844 if( varclassifier->freeClassifier != NULL )
845 {
846 SCIPdebugMessage("Calling freeClassifier of varclassifier %s\n", varclassifier->name);
847 SCIP_CALL( (*varclassifier->freeClassifier)(conshdlrdata->gcg, varclassifier) );
848 }
849
850 BMSfreeMemoryArray(&varclassifier->name);
851 BMSfreeMemoryArray(&varclassifier->description);
852
853 SCIPfreeBlockMemory(scip, &conshdlrdata->varclassifiers[i]);
854 }
855
856 /* free all scores */
857 for( i = 0; i < conshdlrdata->nscores; ++i )
858 {
859 GCG_SCORE* score = conshdlrdata->scores[i];
860 assert(score != NULL);
861
862 if( score->scorefree != NULL )
863 {
864 SCIPdebugMessage("Calling freeScore of score %s\n", score->name);
865 SCIP_CALL( (*score->scorefree)(conshdlrdata->gcg, score) );
866 }
867
868 BMSfreeMemoryArray(&score->name);
871
872 SCIPfreeBlockMemory(scip, &conshdlrdata->scores[i]);
873 }
874 SCIPfreeClock(scip, &conshdlrdata->scoreclock);
875
876 /* remove all remaining data */
877 SCIPfreeMemoryArray(scip, &conshdlrdata->priorities);
878 SCIPfreeMemoryArray(scip, &conshdlrdata->detectors);
884 SCIPfreeMemoryArray(scip, &conshdlrdata->varclassifiers);
886 SCIPfreeMemoryArray(scip, &conshdlrdata->scores);
887
888 delete conshdlrdata->userblocknrcandidates;
889 delete conshdlrdata->partialdecs;
890 delete conshdlrdata->partialdecsbyid;
891
892 /* remove the data structure of the conshdlr */
893 SCIPfreeMemory(scip, &conshdlrdata);
894
895 return SCIP_OKAY;
896}
897
898
899/** constraint enforcing method of constraint handler for LP solutions */
900static
901SCIP_DECL_CONSENFORELAX(consEnforeDecomp)
902{ /*lint --e{715}*/
903 *result = SCIP_FEASIBLE;
904 return SCIP_OKAY;
905}
906
907
908/** constraint enforcing method of constraint handler for LP solutions */
909static
910SCIP_DECL_CONSENFOLP(consEnfolpDecomp)
911{ /*lint --e{715}*/
912 *result = SCIP_FEASIBLE;
913 return SCIP_OKAY;
914}
915
916
917/** constraint enforcing method of constraint handler for pseudo solutions */
918static
919SCIP_DECL_CONSENFOPS(consEnfopsDecomp)
920{ /*lint --e{715}*/
921 *result = SCIP_FEASIBLE;
922 return SCIP_OKAY;
923}
924
925
926/** feasibility check method of constraint handler for integral solutions */
927static
928SCIP_DECL_CONSCHECK(consCheckDecomp)
929{
930 /*lint --e{715}*/
931 *result = SCIP_FEASIBLE;
932 return SCIP_OKAY;
933}
934
935
936/** variable rounding lock method of constraint handler */
937static
938SCIP_DECL_CONSLOCK(consLockDecomp)
939{ /*lint --e{715}*/
940 return SCIP_OKAY;
941}
942
943
944/**
945 * @brief finds a non duplicate constraint name of the form c_{a} with minimal natural number {a}
946 * @return id of constraint
947 */
948static
950 SCIP* scip, /**< SCIP data structure */
951 int startcount, /**< natural number, lowest candidate number to test */
952 char* consname, /**< char pointer to store the new non-duplicate name */
953 int namelength /**< max length of the name */
954 )
955{
956 int candidatenumber;
957
958 candidatenumber = startcount;
959
960 /* terminates since there are only finitely many constraints and i (for c_i) increases every iteration */
961 while( TRUE )
962 {
963 /* create new name candidate */
964 SCIPsnprintf(consname, SCIP_MAXSTRLEN, "c_%d", candidatenumber);
965
966 /* check candidate, if it is not free increase counter for candidate number */
967 if ( SCIPfindCons(scip, consname) == NULL )
968 return candidatenumber;
969 else
970 ++candidatenumber;
971 }
972 return -1;
973}
974
975
976/** @brief creates a partialdec for a given decomposition
977 *
978 * @returns SCIP return code
979 * */
980static
982 GCG* gcg, /**< GCG data structure */
983 GCG_DECOMP* decomp, /**< decomposition the partialdec is created for */
984 PARTIALDECOMP** newpartialdec /**< the new partialdec created from the decomp */
985 )
986{
987 assert( decomp != NULL );
988 assert( GCGdecompCheckConsistency( gcg, decomp ) );
989
990 /* get detprobdata for var & cons indices */
992
993 /* create new partialdec and initialize its data */
994 PARTIALDECOMP* partialdec = new PARTIALDECOMP(gcg, !decomp->presolved);
995 partialdec->setNBlocks( GCGdecompGetNBlocks(decomp));
996
997 SCIP_CONS** linkingconss = GCGdecompGetLinkingconss(decomp);
998 int nlinkingconss = GCGdecompGetNLinkingconss(decomp);
999 SCIP_HASHMAP* constoblock = GCGdecompGetConstoblock(decomp);
1000 int nblock;
1001
1002 /* set linking conss */
1003 for( int c = 0; c < nlinkingconss; ++c )
1004 {
1005 partialdec->fixConsToMaster(detprobdata->getIndexForCons(linkingconss[c]));
1006 }
1007
1008 /* set block conss */
1009 for( int c = 0; c < detprobdata->getNConss(); ++c )
1010 {
1011 nblock = (int) (size_t) SCIPhashmapGetImage(constoblock, (void*) (size_t) detprobdata->getCons(c));
1012 if( nblock >= 1 && nblock <= partialdec->getNBlocks() )
1013 {
1014 partialdec->fixConsToBlock(c, nblock - 1);
1015 }
1016 }
1017
1018 SCIP_VAR*** stairlinkingvars = GCGdecompGetStairlinkingvars(decomp);
1019
1020 if( stairlinkingvars != NULL )
1021 {
1022 int* nstairlinkingvars = GCGdecompGetNStairlinkingvars(decomp);
1023 int varindex;
1024
1025 /* set stairlinkingvars */
1026 for( int b = 0; b < partialdec->getNBlocks(); ++b )
1027 {
1028 for( int v = 0; v < nstairlinkingvars[b]; ++v )
1029 {
1030 if( stairlinkingvars[b][v] != NULL )
1031 {
1032 varindex = detprobdata->getIndexForVar(stairlinkingvars[b][v]);
1033 partialdec->fixVarToStairlinking(varindex, b);
1034 }
1035 }
1036 }
1037 }
1038
1039 /* set other vars */
1040 SCIP_HASHMAP* vartoblock = GCGdecompGetVartoblock(decomp);
1041 if( vartoblock != NULL )
1042 {
1043 for( int v = 0; v < detprobdata->getNVars(); ++v )
1044 {
1045 nblock = (int) (size_t) SCIPhashmapGetImage(vartoblock,
1046 (void*) (size_t) SCIPvarGetProbvar(detprobdata->getVar(v)));
1047 if( nblock == partialdec->getNBlocks() + 2 && !partialdec->isVarStairlinkingvar(v))
1048 {
1049 partialdec->fixVarToLinking(v);
1050 }
1051 else if( nblock == partialdec->getNBlocks() + 1 )
1052 {
1053 partialdec->fixVarToMaster(v);
1054 }
1055 else if( nblock >= 1 && nblock <= partialdec->getNBlocks())
1056 {
1057 partialdec->fixVarToBlock(v, nblock - 1);
1058 }
1059 }
1060 }
1061
1062 partialdec->sort();
1063
1064 /* now all conss and vars should be assigned */
1065 assert( partialdec->isComplete() );
1066
1067 /*set all detector-related information*/
1068 for( int i = 0; i < GCGdecompGetDetectorChainSize(decomp); ++i )
1069 {
1070 partialdec->setDetectorPropagated(GCGdecompGetDetectorChain(decomp)[i]);
1071 partialdec->addClockTime(GCGdecompGetDetectorClockTimes(decomp)[i]);
1075 partialdec->addPctVarsFromFree(1 - *(GCGdecompGetDetectorPctVarsFromOpen(decomp)));
1078 partialdec->addNNewBlocks(*(GCGdecompGetNNewBlocks(decomp)));
1079 }
1080
1081 if( stairlinkingvars == NULL )
1082 {
1084 }
1085
1086 *newpartialdec = partialdec;
1087 return SCIP_OKAY;
1088}
1089
1090
1091/**
1092 * @brief creates a decomposition GCG_DECOMP structure for a given partialdec
1093 * @returns scip return code
1094 */
1095static
1097 GCG* gcg, /**< GCG data structure */
1098 PARTIALDECOMP* partialdec, /**< partialdec the decomposition is created for */
1099 GCG_DECOMP** newdecomp /**< the new decomp created from the partialdec */
1100 )
1101{
1103 SCIP_HASHMAP* vartoblock = NULL;
1104 SCIP_HASHMAP* constoblock = NULL;
1105 SCIP_HASHMAP* varindex = NULL;
1106 SCIP_HASHMAP* consindex = NULL;
1107 SCIP_VAR*** stairlinkingvars = NULL;
1108 SCIP_VAR*** subscipvars = NULL;
1109 SCIP_VAR** linkingvars = NULL;
1110 SCIP_CONS** linkingconss = NULL;
1111 SCIP_CONS*** subscipconss = NULL;
1112
1113 int* nsubscipconss = NULL;
1114 int* nsubscipvars = NULL;
1115 int* nstairlinkingvars = NULL;
1116 int nlinkingvars;
1117
1118 int varcounter = 1; /* in varindex counting starts with 1 */
1119 int conscounter = 1; /* in consindex counting starts with 1 */
1120 int counterstairlinkingvars = 0;
1121 int modifier;
1122 int nlinkingconss;
1123 int ndeletedblocks = 0;
1124 int nmastervarsfromdeleted = 0;
1125 int v;
1126 int c;
1127
1128 assert( partialdec->checkConsistency() );
1129
1130 DETPROBDATA* detprobdata = partialdec->getDetprobdata();
1131 assert(detprobdata != NULL);
1132
1133 std::vector<SCIP_Bool> isblockdeleted = std::vector<SCIP_Bool>(partialdec->getNBlocks(), FALSE);
1134 std::vector<int> ndeletedblocksbefore = std::vector<int>(partialdec->getNBlocks(), 0);
1135 std::vector<int> mastervaridsfromdeleted = std::vector<int>(0);
1136 std::vector<SCIP_Var*> mastervarsfromdeleted = std::vector<SCIP_VAR*>(0);
1137 std::vector<SCIP_CONS*> relevantconss = detprobdata->getRelevantConss();
1138 std::vector<SCIP_VAR*> relevantvars = detprobdata->getRelevantVars();
1139 std::vector<SCIP_VAR*> origfixedtozerovars = detprobdata->getOrigVarsFixedZero();
1140
1141 /* create decomp data structure */
1142 SCIP_CALL_ABORT( GCGdecompCreate(gcg, newdecomp) );
1143
1144 GCGdecompSetPresolved(*newdecomp, !partialdec->isAssignedToOrigProb());
1145
1146 /* find out if for some blocks all conss have been deleted */
1147 for( int b = 0; b < partialdec->getNBlocks(); ++b )
1148 {
1149 SCIP_Bool iscurblockdeleted = TRUE;
1150 for( c = 0; c < partialdec->getNConssForBlock( b ); ++c )
1151 {
1152 int consid = partialdec->getConssForBlock( b )[c];
1153 SCIP_CONS* scipcons = relevantconss[consid];
1154
1155 if( scipcons != NULL && !SCIPconsIsDeleted( scipcons) )
1156 {
1157 iscurblockdeleted = FALSE;
1158 break;
1159 }
1160 }
1161 if ( iscurblockdeleted )
1162 {
1163 ++ndeletedblocks;
1164 isblockdeleted[b] = TRUE;
1165 for( int b2 = b+1; b2 < partialdec->getNBlocks(); ++b2)
1166 {
1167 ++ndeletedblocksbefore[b2];
1168 }
1169 /* store deletion information of included vars */
1170 for( v = 0; v < partialdec->getNVarsForBlock( b ); ++v )
1171 {
1172 int varid = partialdec->getVarsForBlock( b )[v];
1173 SCIP_VAR* scipvar = relevantvars[varid];
1174 mastervaridsfromdeleted.push_back(varid);
1175 mastervarsfromdeleted.push_back(scipvar);
1176 ++nmastervarsfromdeleted;
1177 }
1178 }
1179 }
1180
1181 /* set nblocks */
1182 GCGdecompSetNBlocks( *newdecomp, partialdec->getNBlocks() - ndeletedblocks );
1183
1184 if( partialdec->getNBlocks() - ndeletedblocks == 0 )
1185 {
1186 SCIPverbMessage(scip, SCIP_VERBLEVEL_NORMAL, NULL, "All blocks have been deleted since only deleted constraints are contained, no reformulation is done.\n");
1187 }
1188
1189 /* prepare constraints data structures */
1190 if( partialdec->getNMasterconss() != 0 )
1191 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &linkingconss, partialdec->getNMasterconss()) );
1192 else
1193 linkingconss = NULL;
1194
1195 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &nsubscipconss, partialdec->getNBlocks() - ndeletedblocks) );
1196 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &subscipconss, partialdec->getNBlocks() - ndeletedblocks) );
1197
1198 SCIP_CALL_ABORT( SCIPhashmapCreate(&constoblock, SCIPblkmem(scip), partialdec->getNConss()) );
1199 SCIP_CALL_ABORT( SCIPhashmapCreate(&consindex, SCIPblkmem(scip), partialdec->getNConss()) );
1200
1201 /* set linking constraints */
1202 modifier = 0;
1203 nlinkingconss = partialdec->getNMasterconss();
1204 for( c = 0; c < partialdec->getNMasterconss(); ++c )
1205 {
1206 int consid = partialdec->getMasterconss()[c];
1207 SCIP_CONS* scipcons = relevantconss[consid];
1208 if( partialdec->isAssignedToOrigProb() )
1209 SCIPgetTransformedCons(scip, scipcons, &scipcons);
1210
1211 if( scipcons == NULL || SCIPconsIsDeleted(scipcons) || SCIPconsIsObsolete(scipcons) )
1212 {
1213 --nlinkingconss;
1214 ++modifier;
1215 }
1216 else
1217 {
1218 linkingconss[c-modifier] = scipcons;
1219 SCIP_CALL_ABORT( SCIPhashmapInsert(constoblock, scipcons, (void*) (size_t)(partialdec->getNBlocks() + 1 - ndeletedblocks)) );
1220 SCIP_CALL_ABORT( SCIPhashmapInsert(consindex, scipcons, (void*) (size_t) conscounter ) );
1221 conscounter ++;
1222 }
1223 }
1224
1225 if( nlinkingconss != 0 )
1226 GCGdecompSetLinkingconss(gcg, *newdecomp, linkingconss, nlinkingconss);
1227 else
1228 linkingconss = NULL;
1229
1230 /* set block constraints */
1231 for( int b = 0; b < partialdec->getNBlocks(); ++ b )
1232 {
1233 if( isblockdeleted[b] )
1234 continue;
1235 modifier = 0;
1236 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &subscipconss[b-ndeletedblocksbefore[b]], partialdec->getNConssForBlock(b)) );
1237 nsubscipconss[b-ndeletedblocksbefore[b]] = partialdec->getNConssForBlock(b);
1238 for( c = 0; c < partialdec->getNConssForBlock(b); ++c )
1239 {
1240 int consid = partialdec->getConssForBlock(b)[c];
1241 SCIP_CONS* scipcons = relevantconss[consid];
1242 if( partialdec->isAssignedToOrigProb() )
1243 SCIPgetTransformedCons(scip, scipcons, &scipcons);
1244
1245 if( scipcons == NULL || SCIPconsIsDeleted(scipcons) )
1246 {
1247 --nsubscipconss[b-ndeletedblocksbefore[b]];
1248 ++modifier;
1249 }
1250 else
1251 {
1252 assert( scipcons != NULL );
1253 subscipconss[b-ndeletedblocksbefore[b]][c-modifier] = scipcons;
1254 SCIPdebugMessage("Set cons %s to block %d + 1 - %d in cons to block\n", SCIPconsGetName(scipcons), b, ndeletedblocksbefore[b] );
1255 SCIP_CALL_ABORT( SCIPhashmapInsert(constoblock, scipcons, (void*) (size_t)(b + 1 - ndeletedblocksbefore[b])) );
1256 SCIP_CALL_ABORT( SCIPhashmapInsert(consindex, scipcons, (void*) (size_t) conscounter) );
1257 conscounter ++;
1258 }
1259 }
1260 }
1261
1262 /* assign all open conss that might be left */
1263 for( c = 0; c < SCIPgetNConss(scip); ++c )
1264 {
1266 {
1267 if(!SCIPhashmapExists(constoblock, SCIPgetConss(scip)[c]))
1268 {
1269 SCIP_CONS* scipcons = SCIPgetConss(scip)[c];
1270 SCIP_CALL_ABORT( SCIPhashmapInsert(constoblock, scipcons, (void*) (size_t)(partialdec->getNBlocks() + 1 - ndeletedblocks)) );
1271 SCIP_CALL_ABORT( SCIPhashmapInsert(consindex, scipcons, (void*) (size_t) conscounter) );
1272 conscounter ++;
1273 }
1274 }
1275 }
1276
1277 GCGdecompSetSubscipconss(gcg, *newdecomp, subscipconss, nsubscipconss);
1278 GCGdecompSetConstoblock(*newdecomp, constoblock);
1279 GCGdecompSetConsindex(*newdecomp, consindex);
1280 /* finished setting constraint data structures */
1281
1282 /* prepare constraints data structures */
1283 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &nsubscipvars, partialdec->getNBlocks() - ndeletedblocks) );
1284 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &subscipvars, partialdec->getNBlocks() - ndeletedblocks) );
1285 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &nstairlinkingvars, partialdec->getNBlocks() - ndeletedblocks) );
1286 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &stairlinkingvars, partialdec->getNBlocks() -ndeletedblocks) );
1287
1288 SCIP_CALL_ABORT( SCIPhashmapCreate(&vartoblock, SCIPblkmem(scip), partialdec->getNVars() + (int) origfixedtozerovars.size()) );
1289 SCIP_CALL_ABORT( SCIPhashmapCreate(&varindex, SCIPblkmem(scip), partialdec->getNVars() + (int) origfixedtozerovars.size()) );
1290
1291 /* set linkingvars */
1292 nlinkingvars = partialdec->getNLinkingvars() + partialdec->getNMastervars() + partialdec->getNTotalStairlinkingvars() + nmastervarsfromdeleted + (int) origfixedtozerovars.size();
1293
1294 if( nlinkingvars != 0 )
1295 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &linkingvars, nlinkingvars) );
1296 else
1297 linkingvars = NULL;
1298
1299 for( v = 0; v < partialdec->getNLinkingvars(); ++ v )
1300 {
1301 int var = partialdec->getLinkingvars()[v];
1302 SCIP_VAR* scipvar = SCIPvarGetProbvar(relevantvars[var]);
1303 assert( scipvar != NULL );
1304
1305 linkingvars[v] = scipvar;
1306 SCIPdebugMessage( "Set var %s to block %d + 2 - %d in var to block\n", SCIPvarGetName(scipvar), partialdec->getNBlocks(), ndeletedblocks );
1307 SCIP_CALL_ABORT( SCIPhashmapInsert(vartoblock, scipvar, (void*) (size_t)(partialdec->getNBlocks() + 2 - ndeletedblocks)) );
1308 SCIP_CALL_ABORT( SCIPhashmapInsert(varindex, scipvar, (void*) (size_t) varcounter) );
1309 varcounter ++;
1310 }
1311
1312 for( v = 0; v < partialdec->getNMastervars(); ++ v )
1313 {
1314 int var = partialdec->getMastervars()[v];
1315 SCIP_VAR* scipvar = SCIPvarGetProbvar( relevantvars[var] );
1316 linkingvars[v + partialdec->getNLinkingvars()] = scipvar;
1317 SCIP_CALL_ABORT( SCIPhashmapInsert(vartoblock, scipvar, (void*) (size_t)(partialdec->getNBlocks() + 1 - ndeletedblocks)) );
1318 SCIP_CALL_ABORT( SCIPhashmapInsert(varindex, scipvar, (void*) (size_t) varcounter) );
1319 varcounter ++;
1320 }
1321
1322 for( v = 0; v < nmastervarsfromdeleted; ++v)
1323 {
1324 SCIP_VAR* var;
1325 var = SCIPvarGetProbvar(mastervarsfromdeleted[v]);
1326
1327 linkingvars[partialdec->getNMastervars() + partialdec->getNLinkingvars() + v] = var;
1328 SCIP_CALL_ABORT( SCIPhashmapInsert(vartoblock, var, (void*) (size_t)(partialdec->getNBlocks() + 1 - ndeletedblocks)) );
1329 SCIP_CALL_ABORT( SCIPhashmapInsert(varindex, var, (void*) (size_t) varcounter) );
1330 varcounter ++;
1331 }
1332
1333 for( v = 0; v < (int) origfixedtozerovars.size(); ++v)
1334 {
1335 SCIP_VAR* var;
1336 var = origfixedtozerovars[v];
1337
1338 linkingvars[partialdec->getNMastervars() + partialdec->getNLinkingvars() + nmastervarsfromdeleted + v] = var;
1339 SCIP_CALL_ABORT( SCIPhashmapInsert(vartoblock, var, (void*) (size_t)(partialdec->getNBlocks() + 1 - ndeletedblocks)) );
1340 SCIP_CALL_ABORT( SCIPhashmapInsert(varindex, var, (void*) (size_t) varcounter) );
1341 varcounter ++;
1342 }
1343
1344 /* set block variables */
1345 for( int b = 0; b < partialdec->getNBlocks(); ++ b )
1346 {
1347 if( isblockdeleted[b] )
1348 continue;
1349
1350 if( partialdec->getNVarsForBlock( b ) > 0 )
1351 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, & subscipvars[b -ndeletedblocksbefore[b]], partialdec->getNVarsForBlock(b)) );
1352 else
1353 subscipvars[b-ndeletedblocksbefore[b]] = NULL;
1354
1355 if( partialdec->getNStairlinkingvars( b ) > 0 )
1356 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, & stairlinkingvars[b-ndeletedblocksbefore[b]], partialdec->getNStairlinkingvars(b)) );
1357 else
1358 stairlinkingvars[b-ndeletedblocksbefore[b]] = NULL;
1359
1360 nsubscipvars[b-ndeletedblocksbefore[b]] = partialdec->getNVarsForBlock(b);
1361 nstairlinkingvars[b-ndeletedblocksbefore[b]] = partialdec->getNStairlinkingvars(b);
1362
1363 for( v = 0; v < partialdec->getNVarsForBlock(b); ++ v )
1364 {
1365 int var = partialdec->getVarsForBlock(b)[v];
1366 SCIP_VAR* scipvar = SCIPvarGetProbvar(relevantvars[var]);
1367 assert( scipvar != NULL );
1368
1369 subscipvars[b-ndeletedblocksbefore[b]][v] = scipvar;
1370 SCIPdebugMessage("Set var %s to block %d + 1 - %d in var to block\n", SCIPvarGetName(scipvar), b, ndeletedblocksbefore[b] );
1371 assert( !SCIPhashmapExists(vartoblock, scipvar) || SCIPhashmapGetImage(vartoblock, scipvar) == (void*) (size_t)(b + 1 - ndeletedblocksbefore[b]) );
1372 SCIP_CALL_ABORT( SCIPhashmapInsert(vartoblock, scipvar, (void*) (size_t)(b + 1 - ndeletedblocksbefore[b])) );
1373 SCIP_CALL_ABORT( SCIPhashmapInsert(varindex, scipvar, (void*) (size_t) varcounter) );
1374 varcounter ++;
1375 }
1376
1377 for( v = 0; v < partialdec->getNStairlinkingvars(b); ++ v )
1378 {
1379 int var = partialdec->getStairlinkingvars(b)[v];
1380 SCIP_VAR* scipvar = SCIPvarGetProbvar(relevantvars[var]);
1381 assert( scipvar != NULL );
1382
1383 stairlinkingvars[b-ndeletedblocksbefore[b]][v] = scipvar;
1384 linkingvars[partialdec->getNLinkingvars() + partialdec->getNMastervars() + nmastervarsfromdeleted + counterstairlinkingvars] = scipvar;
1385 SCIP_CALL_ABORT( SCIPhashmapInsert(vartoblock, scipvar, (void*) (size_t)(partialdec->getNBlocks() + 2 - ndeletedblocks)) );
1386 SCIP_CALL_ABORT( SCIPhashmapInsert(varindex, scipvar, (void*) (size_t) varcounter) );
1387 varcounter ++;
1388 counterstairlinkingvars ++;
1389 }
1390 }
1391
1392 /* if any var is open yet put it in master (in case they were not in relevantvars) */
1393 for( v = 0; v < SCIPgetNVars(scip); ++v )
1394 {
1395 if(!SCIPhashmapExists(vartoblock, SCIPgetVars(scip)[v]))
1396 {
1397 SCIP_VAR* scipvar = SCIPvarGetProbvar( SCIPgetVars(scip)[v] );
1398 SCIP_CALL_ABORT( SCIPhashmapInsert(vartoblock, scipvar, (void*) (size_t)(partialdec->getNBlocks() + 1 - ndeletedblocks)) );
1399 SCIP_CALL_ABORT( SCIPhashmapInsert(varindex, scipvar, (void*) (size_t) varcounter) );
1400 varcounter ++;
1401 }
1402 }
1403
1404 GCGdecompSetSubscipvars(gcg, *newdecomp, subscipvars, nsubscipvars);
1405 GCGdecompSetStairlinkingvars(gcg, *newdecomp, stairlinkingvars, nstairlinkingvars);
1406 GCGdecompSetLinkingvars(gcg, *newdecomp, linkingvars, nlinkingvars, (int) origfixedtozerovars.size(), partialdec->getNMastervars() + nmastervarsfromdeleted);
1407 GCGdecompSetVarindex(*newdecomp, varindex);
1408 GCGdecompSetVartoblock(*newdecomp, vartoblock);
1409
1410 /* //////////////////// free stuff ////////////////////////////// */
1411
1412 /* free vars stuff */
1413 SCIPfreeBufferArrayNull(scip, &linkingvars);
1414 for( int b = partialdec->getNBlocks() - 1 - ndeletedblocks; b >= 0; --b )
1415 {
1416 if( nstairlinkingvars[b] != 0 )
1417 {
1418 SCIPfreeBufferArrayNull(scip, &stairlinkingvars[b]);
1419 }
1420 }
1421
1422 SCIPfreeBufferArrayNull( scip, &stairlinkingvars);
1423 SCIPfreeBufferArrayNull( scip, &nstairlinkingvars);
1424
1425 for( int b = partialdec->getNBlocks() - 1 - ndeletedblocks; b >= 0; --b )
1426 {
1427 if( nsubscipvars[b] != 0 )
1428 {
1429 SCIPfreeBufferArrayNull(scip, &subscipvars[b]);
1430 }
1431 }
1432
1433 SCIPfreeBufferArrayNull( scip, &subscipvars);
1434 SCIPfreeBufferArrayNull( scip, &nsubscipvars);
1435
1436 /* free constraints */
1437 for( int b = partialdec->getNBlocks() - 1 - ndeletedblocks; b >= 0; --b )
1438 {
1439 SCIPfreeBufferArrayNull( scip, &subscipconss[b]);
1440 }
1441 SCIPfreeBufferArrayNull( scip, &subscipconss);
1442
1443 SCIPfreeBufferArrayNull( scip, &nsubscipconss);
1444 SCIPfreeBufferArrayNull( scip, &linkingconss);
1445
1446 /* set detectorchain */
1447 GCGdecompSetDetectorChain(gcg, (*newdecomp), partialdec->getDetectorchain().data(), (int) partialdec->getDetectorchain().size());
1448
1449 /* set last detector in chain as detector that "found" this decomposition */
1450 if(partialdec->getNDetectors() > 0)
1451 GCGdecompSetDetector(*newdecomp, partialdec->getDetectorchain().back());
1452
1453 /* set statistical detector chain data */
1454 GCGdecompSetPartialdecID(*newdecomp, partialdec->getID());
1455 if( partialdec->getNDetectors() > 0 )
1456 {
1457 GCGdecompSetDetectorClockTimes(gcg, *newdecomp, partialdec->getDetectorClockTimes().data());
1458 GCGdecompSetDetectorPctVarsToBorder(gcg, *newdecomp, partialdec->getPctVarsToBorderVector().data());
1459 GCGdecompSetDetectorPctVarsToBlock(gcg, *newdecomp, partialdec->getPctVarsToBlockVector().data());
1460 GCGdecompSetDetectorPctVarsFromOpen(gcg, *newdecomp, partialdec->getPctVarsFromFreeVector().data());
1461 GCGdecompSetDetectorPctConssToBorder(gcg, *newdecomp, partialdec->getPctConssToBorderVector().data());
1462 GCGdecompSetDetectorPctConssToBlock(gcg, *newdecomp, partialdec->getPctConssToBlockVector().data());
1463 GCGdecompSetDetectorPctConssFromOpen(gcg, *newdecomp, partialdec->getPctConssFromFreeVector().data());
1464 GCGdecompSetNNewBlocks(gcg, *newdecomp, partialdec->getNNewBlocksVector().data());
1465 }
1466
1467 /* set dectype */
1468 int newnlinkingvars = GCGdecompGetNLinkingvars((*newdecomp));
1469 int newnlinkingconss = GCGdecompGetNLinkingconss((*newdecomp));
1470
1471 if( newnlinkingvars == partialdec->getNTotalStairlinkingvars() && newnlinkingconss == 0 && newnlinkingvars > 0 )
1472 {
1474 }
1475 else if( newnlinkingvars > 0 || partialdec->getNTotalStairlinkingvars() > 0 )
1476 {
1478 }
1479 else if( newnlinkingconss > 0 )
1480 {
1482 }
1483 else if( newnlinkingconss == 0 && partialdec->getNTotalStairlinkingvars() == 0 )
1484 {
1486 }
1487 else
1488 {
1490 }
1491
1492 /* set max white score */
1493 SCIPdebugMessage(" partialdec maxwhitescore: %f\n", partialdec->getMaxWhiteScore());
1494
1495 GCGdecompSetMaxWhiteScore(gcg, *newdecomp, partialdec->getMaxWhiteScore() );
1496
1497 /* set detector string */
1498 char buffer[SCIP_MAXSTRLEN];
1499 partialdec->buildDecChainString(buffer);
1500 GCGdecompSetDetectorChainString(gcg, *newdecomp, buffer);
1501
1502 if( !partialdec->isAssignedToOrigProb() )
1504
1505 assert(GCGdecompCheckConsistency(gcg, *newdecomp) );
1506
1507 return SCIP_OKAY;
1508}
1509
1510
1511/** @brief sorts all registered partialdecs according to score, descending */
1512static
1514 GCG* gcg /**< GCG data structure */
1515 )
1516{
1517 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
1518 assert(conshdlrdata != NULL);
1519
1520 std::sort(conshdlrdata->partialdecs->begin(), conshdlrdata->partialdecs->end(), [&](PARTIALDECOMP* a, PARTIALDECOMP* b) {return (a->getScore(GCGgetCurrentScore(gcg)) > b->getScore(GCGgetCurrentScore(gcg))); });
1521}
1522
1523
1524/** @brief method to adapt score for orig decomps
1525 * @todo: change score for some parameter settings
1526 *
1527 * @returns new score */
1529 GCG* gcg, /**< GCG data structure */
1530 SCIP_Real oldscore /**< current score (to be updated) */
1531 )
1532{
1533 SCIP_Real score = oldscore;
1534 int method;
1535
1536 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
1537 assert(conshdlrdata != NULL);
1539
1540 SCIP_CALL(SCIPgetIntParam(scip, "detection/origprob/advanced/weightinggpresolvedoriginaldecomps", &method) );
1541
1542 if( method == FRACTION_OF_NNONZEROS )
1543 {
1544 if ( conshdlrdata->detprobdatapres == NULL || conshdlrdata->detprobdataorig == NULL )
1545 return score;
1546
1547 score *= (SCIP_Real) conshdlrdata->detprobdataorig->getNNonzeros() / conshdlrdata->detprobdatapres->getNNonzeros();
1548 }
1549
1550 if( method == FRACTION_OF_NROWS )
1551 {
1552 if ( conshdlrdata->detprobdatapres == NULL || conshdlrdata->detprobdataorig == NULL )
1553 return score;
1554
1555 score *= (SCIP_Real) conshdlrdata->detprobdataorig->getNConss() / conshdlrdata->detprobdatapres->getNConss();
1556 }
1557
1558 if( method == FAVOUR_PRESOLVED )
1559 {
1560 score += 1.;
1561 }
1562
1563 return score;
1564}
1565
1566
1567/** @brief adds constraint partitions with a reduced number of classes */
1568static
1570 GCG* gcg, /**< GCG data structure */
1571 gcg::DETPROBDATA* detprobdata /**< classification is for problem to which these data correspond */
1572 )
1573{
1574 /* set the number of classes the partitions should be reduced to */
1575 int maxnclasses = 0;
1576 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
1578
1579 if( detprobdata->getNConss() + detprobdata->getNVars() >= 50000 )
1580 maxnclasses = conshdlrdata->maxnclassesperpartitionforlargeprobs;
1581 else
1582 maxnclasses = conshdlrdata->maxnclassesperpartition;
1583
1584 for( int partitionid = 0; partitionid < detprobdata->getNConsPartitions(); ++ partitionid )
1585 {
1586 ConsPartition* newpartition = detprobdata->getConsPartition(partitionid)->reduceClasses(maxnclasses);
1587
1588 if( newpartition != NULL )
1589 {
1590 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " Added reduced version of conspartition %s with %d different constraint classes \n",
1591 detprobdata->getConsPartition(partitionid)->getName(), maxnclasses);
1592 detprobdata->addConsPartition(newpartition);
1593 }
1594 }
1595}
1596
1597
1598/** @brief adds variable partitions with a reduced number of classes */
1599static
1601 GCG* gcg, /**< GCG data structure */
1602 gcg::DETPROBDATA* detprobdata /**< classification is for problem to which these data correspond */
1603 )
1604{
1605 /* set the number of classes the partitions should be reduced to */
1606 int maxnclasses = 0;
1607 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
1609
1610 if( detprobdata->getNConss() + detprobdata->getNVars() >= 50000 )
1611 maxnclasses = conshdlrdata->maxnclassesperpartitionforlargeprobs;
1612 else
1613 maxnclasses = conshdlrdata->maxnclassesperpartition;
1614
1615 for( int partitionid = 0; partitionid < detprobdata->getNVarPartitions(); ++ partitionid )
1616 {
1617 VarPartition* newpartition = detprobdata->getVarPartition(partitionid)->reduceClasses(maxnclasses);
1618
1619 if( newpartition != NULL )
1620 {
1621 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " Added reduced version of varpartition %s with %d different variable classes\n",
1622 detprobdata->getVarPartition(partitionid)->getName(), maxnclasses );
1623 detprobdata->addVarPartition(newpartition);
1624 }
1625 }
1626}
1627
1628
1629/** @brief sets detection/enabled setting
1630 * @returns SCIP return code */
1631static
1633 GCG* gcg, /**< SCIP data structure */
1634 SCIP_Bool quiet, /**< should the parameter be set quietly (no output) */
1635 SCIP_Bool enabled /**< should the detection be enabled */
1636 )
1637{
1639 SCIP_CALL( SCIPsetBoolParam(scip, "detection/enabled", enabled) );
1640 if( !quiet )
1641 {
1642 SCIPinfoMessage(scip, NULL, "detection/enabled = %s\n", enabled ? "TRUE" : "FALSE");
1643 }
1644 return SCIP_OKAY;
1645}
1646
1647
1648/** @brief resets the parameters to their default value
1649 * @returns SCIP return code */
1650static
1652 GCG* gcg, /**< SCIP data structure */
1653 SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data structure */
1654 SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
1655 )
1656{ /*lint --e{715}*/
1657 int i;
1658 assert(gcg != NULL);
1659
1661 assert(conshdlrdata != NULL);
1662
1663 SCIP_CALL (SCIPsetIntParam(scip, "detection/maxrounds", 2) );
1664 SCIP_CALL (SCIPsetBoolParam(scip, "detection/origprob/enabled", FALSE) );
1665
1666 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/nnonzeros/enabled", TRUE) );
1667 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/scipconstype/enabled", TRUE) );
1668 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/miplibconstype/enabled", TRUE) );
1669 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamenonumbers/enabled", TRUE) );
1670
1672 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamelevenshtein/enabled", TRUE) );
1673 else
1674 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamelevenshtein/enabled", FALSE) );
1675
1676 for( i = 0; i < conshdlrdata->ndetectors; ++i )
1677 {
1678 SCIP_Result result;
1679
1680 char paramname[SCIP_MAXSTRLEN];
1681 SCIP_Bool paramval;
1682 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN,
1683 "detection/detectors/%s/enabled", conshdlrdata->detectors[i]->name);
1684
1685 SCIP_CALL( SCIPresetParam(scip, paramname) );
1686
1687 result = SCIP_DIDNOTRUN;
1688 if( conshdlrdata->detectors[i]->setParamDefault != NULL )
1689 conshdlrdata->detectors[i]->setParamDefault(conshdlrdata->gcg, conshdlrdata->detectors[i], &result);
1690 if( !quiet )
1691 {
1692 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN,
1693 "detection/detectors/%s/enabled", conshdlrdata->detectors[i]->name);
1694 SCIP_CALL( SCIPgetBoolParam(scip, paramname, &paramval) );
1695 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "%s = %s\n", paramname, paramval == TRUE ? "TRUE" : "FALSE");
1696
1697 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN,
1698 "detection/detectors/%s/finishingenabled", conshdlrdata->detectors[i]->name);
1699 SCIP_CALL( SCIPgetBoolParam(scip, paramname, &paramval) );
1700 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "%s = %s\n", paramname, paramval == TRUE ? "TRUE" : "FALSE");
1701 }
1702 }
1703
1704 setDetectionEnabled(gcg, quiet, TRUE);
1705
1706 return SCIP_OKAY;
1707}
1708
1709
1710/** @brief sets the parameters to aggressive values
1711 *
1712 * @returns SCIP return code */
1713static
1715 GCG* gcg, /**< SCIP data structure */
1716 SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data structure */
1717 SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
1718 )
1719{ /*lint --e{715}*/
1720 int i;
1722
1723 assert(scip != NULL);
1724 assert(conshdlrdata != NULL);
1725
1726
1727 SCIP_CALL (SCIPsetIntParam(scip, "detection/maxrounds", 3) );
1728
1729 SCIP_CALL (SCIPsetBoolParam(scip, "detection/origprob/enabled", TRUE) );
1730
1731 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/nnonzeros/enabled", TRUE) );
1732 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/scipconstype/enabled", TRUE) );
1733 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/miplibconstype/enabled", TRUE) );
1734 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamenonumbers/enabled", TRUE) );
1735
1737 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamelevenshtein/enabled", TRUE) );
1738 else
1739 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamelevenshtein/enabled", FALSE) );
1740
1741 for( i = 0; i < conshdlrdata->ndetectors; ++i )
1742 {
1743 SCIP_Result result;
1744
1745 result = SCIP_DIDNOTRUN;
1746 if( conshdlrdata->detectors[i]->setParamAggressive != NULL )
1747 conshdlrdata->detectors[i]->setParamAggressive(conshdlrdata->gcg, conshdlrdata->detectors[i], &result);
1748
1749 if( !quiet )
1750 {
1751 char paramname[SCIP_MAXSTRLEN];
1752 SCIP_Bool paramval;
1753
1754 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN,
1755 "detection/detectors/%s/enabled", conshdlrdata->detectors[i]->name);
1756 SCIP_CALL( SCIPgetBoolParam(scip, paramname, &paramval) );
1757 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "%s = %s\n", paramname, paramval == TRUE ? "TRUE" : "FALSE");
1758
1759 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN,
1760 "detection/detectors/%s/finishingenabled", conshdlrdata->detectors[i]->name);
1761 SCIP_CALL( SCIPgetBoolParam(scip, paramname, &paramval) );
1762 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "%s = %s\n", paramname, paramval == TRUE ? "TRUE" : "FALSE");
1763 }
1764 }
1765
1766 setDetectionEnabled(gcg, quiet, TRUE);
1767
1768 return SCIP_OKAY;
1769}
1770
1771
1772/** @brief disables detectors
1773 *
1774 * @returns SCIP return code */
1775static
1777 GCG* gcg, /**< SCIP data structure */
1778 SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data structure */
1779 SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
1780 )
1781{ /*lint --e{715}*/
1782 int i;
1784 assert(scip != NULL);
1785 assert(conshdlrdata != NULL);
1786
1787 for( i = 0; i < conshdlrdata->ndetectors; ++i )
1788 {
1789 char paramname[SCIP_MAXSTRLEN];
1790 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", conshdlrdata->detectors[i]->name);
1791
1792 SCIP_CALL( SCIPsetBoolParam(scip, paramname, FALSE) );
1793 if( !quiet )
1794 {
1795 SCIPinfoMessage(scip, NULL, "%s = FALSE\n", paramname);
1796 }
1797 }
1798
1799 for( i = 0; i < conshdlrdata->ndetectors; ++i )
1800 {
1801 char paramname[SCIP_MAXSTRLEN];
1802 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", conshdlrdata->detectors[i]->name);
1803
1804 SCIP_CALL( SCIPsetBoolParam(scip, paramname, FALSE) );
1805 if( !quiet )
1806 {
1807 SCIPinfoMessage(scip, NULL, "%s = FALSE\n", paramname);
1808 }
1809 }
1810
1811 for( i = 0; i < conshdlrdata->ndetectors; ++i )
1812 {
1813 char paramname[SCIP_MAXSTRLEN];
1814 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "detection/detectors/%s/postprocessingenabled", conshdlrdata->detectors[i]->name);
1815
1816 SCIP_CALL( SCIPsetBoolParam(scip, paramname, FALSE) );
1817 if( !quiet )
1818 {
1819 SCIPinfoMessage(scip, NULL, "%s = FALSE\n", paramname);
1820 }
1821 }
1822
1823 setDetectionEnabled(gcg, quiet, FALSE);
1824
1825 return SCIP_OKAY;
1826}
1827
1828
1829/** @brief sets the parameters to fast values
1830 *
1831 * @returns SCIP return code */
1832static
1834 GCG* gcg, /**< SCIP data structure */
1835 SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data structure */
1836 SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
1837 )
1838{ /*lint --e{715} */
1839 int i;
1841
1842 assert(scip != NULL);
1843 assert(conshdlrdata != NULL);
1844
1845 SCIP_CALL (SCIPsetIntParam(scip, "detection/maxrounds", 1) );
1846
1847 SCIP_CALL (SCIPsetBoolParam(scip, "detection/origprob/enabled", FALSE) );
1848 SCIP_CALL (SCIPsetBoolParam(scip, "detection/origprob/classificationenabled", FALSE) );
1849
1850 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/nnonzeros/enabled", TRUE) );
1851 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/scipconstype/enabled", TRUE) );
1852 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/miplibconstype/enabled", TRUE) );
1853 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamenonumbers/enabled", TRUE) );
1854
1856 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamelevenshtein/enabled", TRUE) );
1857 else
1858 SCIP_CALL(SCIPsetBoolParam(scip, "detection/classification/consclassifier/consnamelevenshtein/enabled", FALSE) );
1859
1860 for( i = 0; i < conshdlrdata->ndetectors; ++i )
1861 {
1862 SCIP_Result result;
1863
1864 result = SCIP_DIDNOTRUN;
1865 if( conshdlrdata->detectors[i]->overruleemphasis )
1866 continue;
1867
1868 if( conshdlrdata->detectors[i]->setParamFast != NULL )
1869 conshdlrdata->detectors[i]->setParamFast(conshdlrdata->gcg, conshdlrdata->detectors[i], &result);
1870 if( !quiet )
1871 {
1872 char paramname[SCIP_MAXSTRLEN];
1873 SCIP_Bool paramval;
1874
1875 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN,
1876 "detection/detectors/%s/enabled", conshdlrdata->detectors[i]->name);
1877 SCIP_CALL( SCIPgetBoolParam(scip, paramname, &paramval) );
1878 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "%s = %s\n", paramname, paramval == TRUE ? "TRUE" : "FALSE");
1879
1880 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN,
1881 "detection/detectors/%s/finishingenabled", conshdlrdata->detectors[i]->name);
1882 SCIP_CALL( SCIPgetBoolParam(scip, paramname, &paramval) );
1883 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "%s = %s\n", paramname, paramval == TRUE ? "TRUE" : "FALSE");
1884 }
1885 }
1886
1887 setDetectionEnabled(gcg, quiet, TRUE);
1888
1889 return SCIP_OKAY;
1890}
1891
1892
1893/** @brief method to calculate the greatest common divisor
1894 * @returns greatest common divisor
1895 */
1896static
1898 int a, /**< first value */
1899 int b /**< second value */
1900 )
1901{
1902 return b == 0 ? a : gcd( b, a % b );
1903}
1904
1905
1906 /** */
1907static
1908SCIP_DECL_PARAMCHGD(paramChgdScore)
1909{
1910 SCIP_CONSHDLR* conshdlr;
1911 SCIP_CONSHDLRDATA* conshdlrdata;
1912
1913 conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
1914 conshdlrdata = SCIPconshdlrGetData(conshdlr);
1915 assert(conshdlrdata != NULL);
1916
1917 char* shortname;
1918
1919 shortname = SCIPparamGetString(param);
1920
1921 for( int i = 0; i < conshdlrdata->nscores; ++i )
1922 {
1923 GCG_SCORE* score;
1924 score = conshdlrdata->scores[i];
1925
1926 assert(score != NULL);
1927
1928 if( strcmp(score->shortname, shortname) == 0 )
1929 {
1930 return SCIP_OKAY;
1931 }
1932 }
1933
1934 SCIPdialogMessage(scip, NULL, "The score <%s> does not exist.\n", shortname);
1935 SCIPdialogMessage(scip, NULL, "The default score <%s> is selected.\n", DEFAULT_SCORE);
1936
1937 SCIPsetStringParam(scip, "detection/scores/selected", DEFAULT_SCORE);
1938
1939 return SCIP_OKAY;
1940}
1941
1942
1943/* --------------- public functions --------------- */
1944
1945/* prints block candidate information (gcg.h) */
1947 GCG* gcg,
1948 FILE* file
1949 )
1950{
1951 gcg::DETPROBDATA* detprobdata;
1953 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
1954 assert(conshdlrdata != NULL);
1955
1956 detprobdata = (conshdlrdata->detprobdatapres == NULL ? conshdlrdata->detprobdataorig : conshdlrdata->detprobdatapres );
1957
1958 if( detprobdata == NULL )
1959 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), NULL, "No block number candidates are calculated yet, consider detecting first.. \n" );
1960 else
1961 detprobdata->printBlockcandidateInformation(file);
1962
1963 return SCIP_OKAY;
1964}
1965
1966
1967/* prints detection time (gcg.h) */
1969 GCG* gcg,
1970 FILE* file
1971 )
1972{
1974 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "DETECTIONTIME \n" );
1976
1977 return SCIP_OKAY;
1978}
1979
1980
1981/* prints partition information (gcg.h) */
1983 GCG* gcg,
1984 FILE* file
1985 )
1986{
1987 gcg::DETPROBDATA* detprobdata;
1988 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
1989 assert(conshdlrdata != NULL);
1990
1991 detprobdata = (conshdlrdata->detprobdatapres == NULL ? conshdlrdata->detprobdataorig : conshdlrdata->detprobdatapres );
1992
1993 detprobdata->printPartitionInformation(file);
1994
1995 return SCIP_OKAY;
1996}
1997
1998
1999/* prints decomp information (gcg.h) */
2001 GCG* gcg,
2002 FILE* file
2003 )
2004{
2005 std::vector<gcg::PARTIALDECOMP*>::const_iterator partialdeciter;
2006 std::vector<gcg::PARTIALDECOMP*>::const_iterator partialdeciterend;
2008
2010
2011 std::vector<PARTIALDECOMP*> partialdeclist;
2012 getFinishedPartialdecs(gcg, partialdeclist);
2013 partialdeciter = partialdeclist.begin();
2014 partialdeciterend = partialdeclist.end();
2015
2016 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "DECOMPINFO \n" );
2017 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", (int) partialdeclist.size() );
2018
2019 for( ; partialdeciter != partialdeciterend; ++partialdeciter )
2020 {
2021 gcg::PARTIALDECOMP* partialdec;
2022 int nblocks = (*partialdeciter)->getNBlocks();
2023
2024 partialdec = *partialdeciter;
2025
2026 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "NEWDECOMP \n");
2027 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", (*partialdeciter)->getNBlocks());
2028 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", (*partialdeciter)->getID());
2029 for( int block = 0; block < nblocks; ++block )
2030 {
2031 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", partialdec->getNConssForBlock(block));
2032 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", partialdec->getNVarsForBlock(block));
2033 }
2034 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", partialdec->getNMasterconss());
2035 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", partialdec->getNLinkingvars());
2036 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", partialdec->getNMastervars());
2038 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%f\n", partialdec->getMaxWhiteScore());
2039 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%f\n", partialdec->getScore(GCGconshdlrDecompFindScore(gcg, "classic")));
2040 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%f\n", partialdec->getScore(GCGconshdlrDecompFindScore(gcg, "max foreseeing white")));
2042 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "%d\n", (int) partialdec->getDetectorchain( ).size());
2043 for( int detector = 0; detector <(int) partialdec->getDetectorchain().size(); ++ detector )
2044 {
2046 GCGdetectorGetName(partialdec->getDetectorchain()[detector]));
2047 }
2048 partialdec->printPartitionInformation(file);
2049 }
2050
2051 return SCIP_OKAY;
2052}
2053
2054
2055/* gets number of partialdecs for public interface (pub_decomp.h)*/
2057 GCG* gcg
2058 )
2059{
2061}
2062
2063
2065 GCG_DETECTOR* detector
2066 )
2067{
2068 if( detector == NULL )
2069 return '0';
2070 else
2071 return detector->decchar;
2072}
2073
2074
2076 GCG_DETECTOR* detector
2077 )
2078{
2079 assert(detector != NULL);
2080 return detector->decdata;
2081}
2082
2083
2085 GCG_DETECTOR* detector
2086 )
2087{
2088 assert(detector != NULL);
2089 return detector->name;
2090}
2091
2092
2094 GCG* gcg,
2095 SCIP_RESULT* result
2096 )
2097{
2098 SCIP* origprob = GCGgetOrigprob(gcg);
2099 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2100
2101 SCIP_CALL(SCIPresetClock(origprob, conshdlrdata->completedetectionclock));
2102 SCIP_CALL(SCIPstartClock(origprob, conshdlrdata->completedetectionclock));
2103
2104 *result = SCIP_DIDNOTRUN;
2105
2106 if( conshdlrdata->detprobdataorig == NULL )
2107 {
2109 }
2110
2111 /* if there are no entries there cannot be a structure */
2112 if( SCIPgetNOrigVars(origprob) == 0 && SCIPgetNOrigConss(origprob) == 0 )
2113 return SCIP_OKAY;
2114
2115 /* if the original problem should be solved, then no decomposition will be performed */
2117 return SCIP_OKAY;
2118
2119 /* if there should not be any detection, stop at this point */
2120 if(!conshdlrdata->enabled)
2121 {
2122 return SCIP_OKAY;
2123 }
2124
2125 ////////////////////
2126 ///// ORIGINAL /////
2127 ////////////////////
2128
2129 SCIP_Bool calculateOrigDecomps;
2130 SCIP_Bool classifyOrig;
2131
2132 SCIPgetBoolParam(origprob, "detection/origprob/enabled", &calculateOrigDecomps);
2133 SCIPgetBoolParam(origprob, "detection/origprob/classificationenabled", &classifyOrig);
2134 if (SCIPgetStage(origprob) < SCIP_STAGE_PRESOLVED) {
2135 if (calculateOrigDecomps) {
2136 // if there is no root partialdec yet, add root partialdec
2137 if( conshdlrdata->detprobdataorig->getOpenPartialdecs().empty() )
2138 {
2139 PARTIALDECOMP* rootpartialdec = new PARTIALDECOMP(gcg, true);
2140 bool success = conshdlrdata->detprobdataorig->addPartialdecToOpen(rootpartialdec);
2141 if( !success )
2142 {
2143 SCIPerrorMessage("Could not add root partialdecomp to the pool of open decompositions.");
2144 return SCIP_ERROR;
2145 }
2146 }
2147
2148 SCIPdebugMessage("is stage < transformed ? %s -> do %s transformProb() ", (SCIPgetStage(origprob) < SCIP_STAGE_TRANSFORMED ? "yes" : "no"), (SCIPgetStage(origprob) < SCIP_STAGE_TRANSFORMED ? "" : "not") );
2149
2150 if( SCIPgetStage(origprob) < SCIP_STAGE_TRANSFORMED )
2151 SCIP_CALL(SCIPtransformProb(origprob));
2152
2153 // TODO ref classify (introduce flag for each detector and check whether this is needed)
2154
2155 // CLASSIFICATION
2156 if( classifyOrig )
2157 {
2159 if( SCIPgetVerbLevel(origprob) >= SCIP_VERBLEVEL_FULL )
2161 }
2162 else
2163 SCIPdebugMessage("classification for orig problem disabled \n" );
2164
2165 // BLOCK CANDIDATES
2167
2168 // FIND DECOMPOSITIONS
2169 SCIPdebugMessage("start finding decompositions for original problem!\n" );
2170 SCIPverbMessage(origprob, SCIP_VERBLEVEL_NORMAL, NULL, "start finding decompositions for original problem!\n");
2171 SCIP_CALL(SCIPresetClock(origprob, conshdlrdata->detectorclock));
2172 SCIP_CALL(SCIPstartClock(origprob, conshdlrdata->detectorclock));
2173 detect(gcg, conshdlrdata->detprobdataorig);
2174 SCIP_CALL(SCIPstopClock(origprob, conshdlrdata->detectorclock));
2175 SCIPverbMessage(origprob, SCIP_VERBLEVEL_NORMAL, NULL, "finished finding decompositions for original problem!\n");
2176 SCIPdebugMessage("finished finding decompositions for original problem!\n" );
2177 }
2178 else
2179 SCIPdebugMessage("finding decompositions for original problem is NOT enabled!\n");
2180
2181 std::vector<SCIP_CONS*> indexToCons; /* stores the corresponding scip constraints pointer */
2182 std::vector<gcg::PARTIALDECOMP*> partialdecsorig(0); /* partialdecs that were found for the orig problem */
2183
2184 SCIP_CALL(SCIPstopClock(origprob, conshdlrdata->completedetectionclock));
2185 conshdlrdata->hasrunoriginal = TRUE;
2186 conshdlrdata->detprobdataorig->freeTemporaryData();
2187 }
2188 else
2189 { // SCIPgetStage(scip) >= SCIP_STAGE_PRESOLVED
2190 //////////////////////////////////////
2191 ///// TRANSFORMED / IS PRESOLVED /////
2192 //////////////////////////////////////
2193
2194 /* detection for presolved problem */
2195
2196 if( SCIPgetStage(origprob) == SCIP_STAGE_INIT || SCIPgetNVars(origprob) == 0 || SCIPgetNConss(origprob) == 0 )
2197 {
2198 SCIPverbMessage(origprob, SCIP_VERBLEVEL_DIALOG, NULL, "No problem exists, cannot detect structure!\n");
2199
2200 /* presolving removed all constraints or variables */
2201 if (SCIPgetNVars(origprob) == 0 || SCIPgetNConss(origprob) == 0)
2202 conshdlrdata->hasrun = TRUE;
2203
2204 *result = SCIP_DIDNOTRUN;
2205 return SCIP_OKAY;
2206 }
2207
2208 /* start detection clocks */
2209 SCIP_CALL(SCIPresetClock(origprob, conshdlrdata->completedetectionclock));
2210 SCIP_CALL(SCIPstartClock(origprob, conshdlrdata->completedetectionclock));
2211
2212 /* Classification */
2215
2216 /* add block number candidates of the original problem */
2217 if( conshdlrdata->detprobdataorig )
2218 {
2219 for( auto& candidatesNBlock : conshdlrdata->detprobdataorig->candidatesNBlocks )
2220 conshdlrdata->detprobdatapres->addCandidatesNBlocksNVotes(candidatesNBlock.first, candidatesNBlock.second);
2221 }
2222
2223 /* add root partialdec */
2224 if( conshdlrdata->detprobdatapres->getOpenPartialdecs().empty() )
2225 {
2226 PARTIALDECOMP* rootpartialdec = new PARTIALDECOMP(gcg, false);
2227
2228 bool success = conshdlrdata->detprobdatapres->addPartialdecToOpen(rootpartialdec);
2229 assert(success);
2230 if( !success )
2231 {
2232 SCIPerrorMessage("Could not add root decomposition.");
2233 *result = SCIP_DIDNOTRUN;
2234 return SCIP_ERROR;
2235 }
2236 }
2237
2238 SCIP_CALL(SCIPresetClock(origprob, conshdlrdata->detectorclock));
2239 SCIP_CALL(SCIPstartClock(origprob, conshdlrdata->detectorclock));
2240 detect(gcg, conshdlrdata->detprobdatapres);
2241 SCIP_CALL(SCIPstopClock(origprob, conshdlrdata->detectorclock));
2242 conshdlrdata->detprobdatapres->sortFinishedForScore();
2243 SCIP_CALL(SCIPstopClock(origprob, conshdlrdata->completedetectionclock));
2244 conshdlrdata->hasrun = TRUE;
2245 conshdlrdata->detprobdatapres->freeTemporaryData();
2246 }
2247
2248 /////////////////////////
2249 ///// EVAL SUCCESS //////
2250 /////////////////////////
2251
2252 if( conshdlrdata->detprobdatapres != NULL && conshdlrdata->detprobdatapres->getNFinishedPartialdecs() > 0 )
2253 *result = SCIP_SUCCESS;
2254
2255 if( conshdlrdata->detprobdataorig != NULL && conshdlrdata->detprobdataorig->getNFinishedPartialdecs() > 0 )
2256 *result = SCIP_SUCCESS;
2257
2258 SCIPdebugMessage("Detection took %fs\n", SCIPgetClockTime( origprob, conshdlrdata->detectorclock));
2259
2260 if( conshdlrdata->detprobdatapres != NULL && SCIPgetVerbLevel(origprob) >= SCIP_VERBLEVEL_FULL )
2262
2263 /* display timing statistics */
2265 /** @todo put this output to the statistics output */
2266
2267 if( *result == SCIP_DIDNOTRUN )
2268 {
2269 return SCIP_OKAY;
2270 }
2271
2272 /* show that we have done our duty */
2273 *result = SCIP_SUCCESS;
2274
2275 return SCIP_OKAY;
2276}
2277
2278
2280 GCG* gcg,
2281 const char* name
2282 )
2283{
2284 SCIP_CONSHDLRDATA* conshdlrdata;
2285 int i;
2286
2287 conshdlrdata = getConshdlrdata(gcg);
2288 assert(conshdlrdata != NULL);
2289
2290 for( i = 0; i < conshdlrdata->nconsclassifiers; ++i )
2291 {
2292 GCG_CONSCLASSIFIER *classifier;
2293 classifier = conshdlrdata->consclassifiers[i];
2294 assert(classifier != NULL);
2295 if( strcmp(classifier->name, name) == 0 )
2296 {
2297 return classifier;
2298 }
2299 }
2300
2301 return NULL;
2302}
2303
2304
2306 GCG* gcg,
2307 const char* name
2308 )
2309{
2310 SCIP_CONSHDLRDATA* conshdlrdata;
2311 int i;
2312
2313 conshdlrdata = getConshdlrdata(gcg);
2314 assert(conshdlrdata != NULL);
2315
2316 for( i = 0; i < conshdlrdata->nvarclassifiers; ++i )
2317 {
2318 GCG_VARCLASSIFIER *classifier;
2319 classifier = conshdlrdata->varclassifiers[i];
2320 assert(classifier != NULL);
2321 if( strcmp(classifier->name, name) == 0 )
2322 {
2323 return classifier;
2324 }
2325 }
2326
2327 return NULL;
2328}
2329
2330
2332 GCG* gcg,
2333 const char* name
2334 )
2335{
2336 SCIP_CONSHDLRDATA* conshdlrdata;
2337 int i;
2338
2339 conshdlrdata = getConshdlrdata(gcg);
2340 assert(conshdlrdata != NULL);
2341
2342 for( i = 0; i < conshdlrdata->ndetectors; ++i )
2343 {
2344 GCG_DETECTOR* detector;
2345 detector = conshdlrdata->detectors[i];
2346 assert(detector != NULL);
2347 if( strcmp(detector->name, name) == 0 )
2348 {
2349 return detector;
2350 }
2351 }
2352
2353 return NULL;
2354}
2355
2356
2358 GCG* gcg,
2359 const char* name
2360 )
2361{
2362 SCIP_CONSHDLRDATA* conshdlrdata;
2363 int i;
2364
2365 assert(name != NULL);
2366
2367 conshdlrdata = getConshdlrdata(gcg);
2368 assert(conshdlrdata != NULL);
2369
2370 for( i = 0; i < conshdlrdata->nscores; ++i )
2371 {
2372 GCG_SCORE* score;
2373 score = conshdlrdata->scores[i];
2374 assert(score != NULL);
2375 if( strcmp(score->name, name) == 0 )
2376 {
2377 return score;
2378 }
2379 }
2380
2381 return NULL;
2382}
2383
2384
2386 GCG* gcg,
2387 const char* shortname
2388 )
2389{
2390 SCIP_CONSHDLRDATA* conshdlrdata;
2391 int i;
2392
2393 assert(shortname != NULL);
2394
2395 conshdlrdata = getConshdlrdata(gcg);
2396 assert(conshdlrdata != NULL);
2397
2398 for( i = 0; i < conshdlrdata->nscores; ++i )
2399 {
2400 GCG_SCORE* score;
2401 score = conshdlrdata->scores[i];
2402 assert(score != NULL);
2403 if( strcmp(score->shortname, shortname) == 0 )
2404 {
2405 return score;
2406 }
2407 }
2408
2409 return NULL;
2410}
2411
2412
2414 GCG* gcg,
2415 SCIP_Bool printwarnings
2416 )
2417{
2419 GCG_DECOMP* decomp;
2420 PARTIALDECOMP* partialdec;
2421 std::vector<std::pair<PARTIALDECOMP*, SCIP_Real> > candidates;
2422
2424 return NULL;
2425
2426 GCGconshdlrDecompChooseCandidatesFromSelected(gcg, candidates, FALSE, printwarnings);
2427 if ( candidates.empty() )
2428 return NULL;
2429
2430 partialdec = candidates[0].first;
2431
2432 assert( !partialdec->isAssignedToOrigProb() );
2433 assert( partialdec->isComplete() );
2434
2435 createDecompFromPartialdec(gcg, partialdec, &decomp);
2436
2437 return decomp;
2438}
2439
2440
2442 GCG* gcg,
2443 SCIP_Bool transformed
2444 )
2445{
2446 int dec;
2447 std::vector<std::pair<PARTIALDECOMP*, SCIP_Real> > candidates;
2448 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2449 assert(conshdlrdata != NULL);
2450
2451 // see if this is a call from functions like e.g. /see GCGwriteAllDecomps
2452 if( conshdlrdata->partialdectowrite != NULL )
2453 {
2454 return conshdlrdata->partialdectowrite;
2455 }
2456
2457 GCGconshdlrDecompChooseCandidatesFromSelected(gcg, candidates, !transformed, TRUE);
2458
2459 // if none was found, output "pure" problem
2460 if( candidates.empty() )
2461 {
2462 int id = GCGconshdlrDecompAddMatrixPartialdec(gcg, transformed);
2464 }
2465
2466 // get the index of the next fitting candidate
2467 for( dec = 0; dec < (int) candidates.size(); ++dec )
2468 {
2469 if( candidates[dec].first->isAssignedToPresolvedProb() == (bool) transformed )
2470 break;
2471 }
2472 // return the candidate iff one was found
2473 if( dec != (int) candidates.size() )
2474 return candidates[dec].first;
2475
2476 return NULL;
2477}
2478
2479
2481 GCG* gcg
2482 )
2483{
2485 SCIP_Real timelimit;
2486 assert(scip != NULL);
2487 SCIP_CALL_ABORT(SCIPgetRealParam(scip, "limits/time", &timelimit));
2488 if( !SCIPisInfinity(scip, timelimit) )
2489 timelimit -= SCIPgetSolvingTime(scip);
2490 return timelimit;
2491}
2492
2493
2495 GCG* gcg,
2496 const char* name,
2497 const char* description,
2498 int priority,
2499 SCIP_Bool enabled,
2500 GCG_CLASSIFIERDATA* classifierdata,
2501 GCG_DECL_FREECONSCLASSIFIER((*freeClassifier)),
2502 GCG_DECL_CONSCLASSIFY((*classify))
2503 )
2504{
2505 GCG_CONSCLASSIFIER* classifier = NULL;
2506 SCIP* origprob;
2507
2508 assert(gcg != NULL);
2509 assert(name != NULL);
2510 assert(description != NULL);
2511
2512 origprob = GCGgetOrigprob(gcg);
2513 assert(origprob != NULL);
2514 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2515
2516 SCIP_CALL( SCIPallocBlockMemory(origprob, &classifier) );
2517 assert(classifier != NULL);
2518
2519 SCIPdebugMessage("Adding classifier %i: %s\n", conshdlrdata->nconsclassifiers+1, name);
2520
2521 SCIP_ALLOC( BMSduplicateMemoryArray(&classifier->name, name, strlen(name)+1) );
2522 SCIP_ALLOC( BMSduplicateMemoryArray(&classifier->description, description, strlen(description)+1) );
2523
2524 classifier->priority = priority;
2525 classifier->enabled = enabled;
2526 classifier->clsdata = classifierdata;
2527
2528 classifier->freeClassifier = freeClassifier;
2529 classifier->classify = classify;
2530
2531 char setstr[SCIP_MAXSTRLEN];
2532 char descstr[SCIP_MAXSTRLEN];
2533 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/classification/consclassifier/%s/enabled", name);
2534 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "flag to indicate whether constraint classifier for <%s> is enabled", description);
2535 SCIP_CALL( SCIPaddBoolParam(origprob, setstr, descstr, &(classifier->enabled), FALSE, enabled, NULL, NULL) );
2536
2537 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->consclassifiers, (size_t)conshdlrdata->nconsclassifiers+1) );
2538 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->consclassifierpriorities,(size_t) conshdlrdata->nconsclassifiers+1) );
2539
2540 conshdlrdata->consclassifiers[conshdlrdata->nconsclassifiers] = classifier;
2541 conshdlrdata->nconsclassifiers = conshdlrdata->nconsclassifiers+1;
2542
2543 return SCIP_OKAY;
2544}
2545
2546
2548 GCG* gcg,
2549 const char* name,
2550 const char decchar,
2551 const char* description,
2552 int freqCallRound,
2553 int maxCallRound,
2554 int minCallRound,
2555 int freqCallRoundOriginal,
2556 int maxCallRoundOriginal,
2557 int minCallRoundOriginal,
2558 int priority,
2559 SCIP_Bool enabled,
2560 SCIP_Bool enabledFinishing,
2561 SCIP_Bool enabledPostprocessing,
2562 SCIP_Bool skip,
2563 SCIP_Bool usefulRecall,
2564 GCG_DETECTORDATA* detectordata,
2565 GCG_DECL_FREEDETECTOR((*freeDetector)),
2566 GCG_DECL_INITDETECTOR((*initDetector)),
2567 GCG_DECL_EXITDETECTOR((*exitDetector)),
2568 GCG_DECL_PROPAGATEPARTIALDEC((*propagatePartialdecDetector)),
2569 GCG_DECL_FINISHPARTIALDEC((*finishPartialdecDetector)),
2570 GCG_DECL_POSTPROCESSPARTIALDEC((*postprocessPartialdecDetector)),
2571 GCG_DECL_SETPARAMAGGRESSIVE((*setParamAggressiveDetector)),
2572 GCG_DECL_SETPARAMDEFAULT((*setParamDefaultDetector)),
2573 GCG_DECL_SETPARAMFAST((*setParamFastDetector))
2574 )
2575{
2576 GCG_DETECTOR* detector = NULL;
2577 char setstr[SCIP_MAXSTRLEN];
2578 char descstr[SCIP_MAXSTRLEN];
2579 SCIP* origprob = GCGgetOrigprob(gcg);
2580 assert(origprob != NULL);
2581
2582 assert(origprob != NULL);
2583 assert(name != NULL);
2584 assert(description != NULL);
2585 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2586
2587 if( conshdlrdata == NULL )
2588 {
2589 SCIPerrorMessage("Decomp constraint handler is not included, cannot add detector!\n");
2590 return SCIP_ERROR;
2591 }
2592
2593 SCIP_CALL( SCIPallocBlockMemory(origprob, &detector) );
2594 assert(detector != NULL);
2595
2596 SCIPdebugMessage("Adding detector %i: %s\n", conshdlrdata->ndetectors+1, name);
2597
2598#ifndef NDEBUG
2599 assert(GCGfindDetector(gcg, name) == NULL);
2600#endif
2601
2602 /* set meta data of detector */
2603 detector->decdata = detectordata;
2604 SCIP_ALLOC( BMSduplicateMemoryArray(&detector->name, name, strlen(name)+1) );
2605 SCIP_ALLOC( BMSduplicateMemoryArray(&detector->description, description, strlen(description)+1) );
2606 detector->decchar = decchar;
2607
2608 /* set memory handling and detection functions */
2609 detector->freeDetector = freeDetector;
2610 detector->initDetector = initDetector;
2611 detector->exitDetector = exitDetector;
2612
2613 /* set functions for editing partialdecs */
2614 detector->propagatePartialdec = propagatePartialdecDetector;
2615 detector->finishPartialdec = finishPartialdecDetector;
2616 detector->postprocessPartialdec = postprocessPartialdecDetector;
2617
2618 /* initialize parameters */
2619 detector->setParamAggressive = setParamAggressiveDetector;
2620 detector->setParamDefault = setParamDefaultDetector;
2621 detector->setParamFast = setParamFastDetector;
2622 detector->freqCallRound = freqCallRound;
2623 detector->maxCallRound = maxCallRound;
2624 detector->minCallRound = minCallRound;
2625 detector->freqCallRoundOriginal = freqCallRoundOriginal;
2626 detector->maxCallRoundOriginal = maxCallRoundOriginal;
2627 detector->minCallRoundOriginal= minCallRoundOriginal;
2628 detector->priority = priority;
2629 detector->enabled = enabled;
2630 detector->enabledFinishing = enabledFinishing;
2631 detector->enabledPostprocessing = enabledPostprocessing;
2632 detector->skip = skip;
2633 detector->usefulRecall = usefulRecall;
2634 detector->overruleemphasis = FALSE;
2635 detector->ndecomps = 0;
2636 detector->ncompletedecomps = 0;
2637 detector->dectime = 0.;
2638
2639 /* add and initialize all parameters accessable from menu */
2640 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
2641 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "flag to indicate whether detector <%s> is enabled", name);
2642 SCIP_CALL( SCIPaddBoolParam(origprob, setstr, descstr, &(detector->enabled), FALSE, enabled, NULL, NULL) );
2643
2644 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
2645 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "flag to indicate whether detector <%s> is enabled for finishing of incomplete decompositions", name);
2646 SCIP_CALL( SCIPaddBoolParam(origprob, setstr, descstr, &(detector->enabledFinishing), FALSE, enabledFinishing, NULL, NULL) );
2647
2648 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/postprocessingenabled", name);
2649 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "flag to indicate whether detector <%s> is enabled for postprocessing of finished decompositions", name);
2650 SCIP_CALL( SCIPaddBoolParam(origprob, setstr, descstr, &(detector->enabledPostprocessing), FALSE, enabledPostprocessing, NULL, NULL) );
2651
2652 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/skip", name);
2653 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "flag to indicate whether detector <%s> should be skipped if others found decompositions", name);
2654 SCIP_CALL( SCIPaddBoolParam(origprob, setstr, descstr, &(detector->skip), FALSE, skip, NULL, NULL) );
2655
2656 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/usefullrecall", name);
2657 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "flag to indicate whether detector <%s> should be called on descendants of the current partialdec", name);
2658 SCIP_CALL( SCIPaddBoolParam(origprob, setstr, descstr, &(detector->usefulRecall), FALSE, usefulRecall, NULL, NULL) );
2659
2660 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/overruleemphasis", name);
2661 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "flag to indicate whether emphasis settings for detector <%s> should be overruled by normal settings", name);
2662 SCIP_CALL( SCIPaddBoolParam(origprob, setstr, descstr, &(detector->overruleemphasis), FALSE, FALSE, NULL, NULL) );
2663
2664 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/freqcallround", name);
2665 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "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 <%s>", name);
2666 SCIP_CALL( SCIPaddIntParam(origprob, setstr, descstr, &(detector->freqCallRound), FALSE, freqCallRound, 0, INT_MAX, NULL, NULL) );
2667
2668 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxcallround", name);
2669 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "maximum round the detector gets called in detection loop <%s>", name);
2670 SCIP_CALL( SCIPaddIntParam(origprob, setstr, descstr, &(detector->maxCallRound), FALSE, maxCallRound, 0, INT_MAX, NULL, NULL) );
2671
2672 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/mincallround", name);
2673 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "minimum round the detector gets called in detection loop <%s>", name);
2674 SCIP_CALL( SCIPaddIntParam(origprob, setstr, descstr, &(detector->minCallRound), FALSE, minCallRound, 0, INT_MAX, NULL, NULL) );
2675
2676 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origfreqcallround", name);
2677 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "frequency the detector gets called in detection loop,i.e., it is called in round r if and only if minCallRound <= r <= maxCallRound AND (r - minCallRound) mod freqCallRound == 0 <%s>", name);
2678 SCIP_CALL( SCIPaddIntParam(origprob, setstr, descstr, &(detector->freqCallRoundOriginal), FALSE, freqCallRoundOriginal, 0, INT_MAX, NULL, NULL) );
2679
2680 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origmaxcallround", name);
2681 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "maximum round the detector gets called in detection loop <%s>", name);
2682 SCIP_CALL( SCIPaddIntParam(origprob, setstr, descstr, &(detector->maxCallRoundOriginal), FALSE, maxCallRoundOriginal, 0, INT_MAX, NULL, NULL) );
2683
2684 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origmincallround", name);
2685 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "minimum round the detector gets called in detection loop <%s>", name);
2686 SCIP_CALL( SCIPaddIntParam(origprob, setstr, descstr, &(detector->minCallRoundOriginal), FALSE, minCallRoundOriginal, 0, INT_MAX, NULL, NULL) );
2687
2688 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/priority", name);
2689 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "priority of detector <%s>", name);
2690 SCIP_CALL( SCIPaddIntParam(origprob, setstr, descstr, &(detector->priority), FALSE, priority, INT_MIN, INT_MAX, NULL, NULL) );
2691
2692 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->detectors, (size_t)conshdlrdata->ndetectors+1) );
2693 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->priorities,(size_t) conshdlrdata->ndetectors+1) );
2694
2695 /* add to detector array */
2696 conshdlrdata->detectors[conshdlrdata->ndetectors] = detector;
2697 conshdlrdata->ndetectors = conshdlrdata->ndetectors+1;
2698
2699 // TODO ref replace propagatePartialdec by more appropriate name once partialdecs are introduced
2700 /* add to propagating detector array if appropriate */
2701 if( detector->propagatePartialdec != NULL )
2702 {
2703 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->propagatingdetectors, (size_t)conshdlrdata->npropagatingdetectors+1) );
2704 conshdlrdata->propagatingdetectors[conshdlrdata->npropagatingdetectors] = detector;
2705 conshdlrdata->npropagatingdetectors = conshdlrdata->npropagatingdetectors+1;
2706 }
2707
2708 // TODO ref replace finishPartialdec by more appropriate name once partialdecs are introduced
2709 /* add to finishing detector array if appropriate */
2710 if( detector->finishPartialdec != NULL )
2711 {
2712 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->finishingdetectors, (size_t)conshdlrdata->nfinishingdetectors+1) );
2713 conshdlrdata->finishingdetectors[conshdlrdata->nfinishingdetectors] = detector;
2714 conshdlrdata->nfinishingdetectors = conshdlrdata->nfinishingdetectors+1;
2715 }
2716
2717 // TODO ref replace postprocessPartialdec by more appropriate name once partialdecs are introduced
2718 /* add to postprocessing detector array if appropriate */
2719 if( detector->postprocessPartialdec != NULL )
2720 {
2721 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->postprocessingdetectors, (size_t)conshdlrdata->npostprocessingdetectors+1) );
2722 conshdlrdata->postprocessingdetectors[conshdlrdata->npostprocessingdetectors] = detector;
2723 conshdlrdata->npostprocessingdetectors = conshdlrdata->npostprocessingdetectors+1;
2724 }
2725
2726 return SCIP_OKAY;
2727}
2728
2729
2731 GCG* gcg,
2732 const char* name,
2733 const char* description,
2734 int priority,
2735 SCIP_Bool enabled,
2736 GCG_CLASSIFIERDATA* classifierdata,
2737 GCG_DECL_FREEVARCLASSIFIER((*freeClassifier)),
2738 GCG_DECL_VARCLASSIFY((*classify))
2739 )
2740{
2741 GCG_VARCLASSIFIER* classifier = NULL;
2742 SCIP* origprob;
2743
2744 assert(gcg != NULL);
2745 assert(name != NULL);
2746 assert(description != NULL);
2747
2748 origprob = GCGgetOrigprob(gcg);
2749 assert(origprob != NULL);
2750
2751 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2752
2753 SCIP_CALL( SCIPallocBlockMemory(origprob, &classifier) );
2754 assert(classifier != NULL);
2755
2756 SCIPdebugMessage("Adding classifier %i: %s\n", conshdlrdata->nvarclassifiers+1, name);
2757
2758 SCIP_ALLOC( BMSduplicateMemoryArray(&classifier->name, name, strlen(name)+1) );
2759 SCIP_ALLOC( BMSduplicateMemoryArray(&classifier->description, description, strlen(description)+1) );
2760
2761 classifier->priority = priority;
2762 classifier->enabled = enabled;
2763 classifier->clsdata = classifierdata;
2764
2765 classifier->freeClassifier = freeClassifier;
2766 classifier->classify = classify;
2767
2768 char setstr[SCIP_MAXSTRLEN];
2769 char descstr[SCIP_MAXSTRLEN];
2770 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/classification/varclassifier/%s/enabled", name);
2771 (void) SCIPsnprintf(descstr, SCIP_MAXSTRLEN, "flag to indicate whether variable classifier for <%s> is enabled", description);
2772 SCIP_CALL( SCIPaddBoolParam(origprob, setstr, descstr, &(classifier->enabled), FALSE, enabled, NULL, NULL) );
2773
2774 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->varclassifiers, (size_t)conshdlrdata->nvarclassifiers+1) );
2775 SCIP_CALL( SCIPreallocMemoryArray(origprob, &conshdlrdata->varclassifierpriorities,(size_t) conshdlrdata->nvarclassifiers+1) );
2776
2777 conshdlrdata->varclassifiers[conshdlrdata->nvarclassifiers] = classifier;
2778 conshdlrdata->nvarclassifiers = conshdlrdata->nvarclassifiers+1;
2779
2780 return SCIP_OKAY;
2781}
2782
2784 GCG* gcg
2785 )
2786{
2787 assert(gcg != NULL);
2788
2789 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2790
2791 assert(conshdlrdata != NULL);
2792
2793 return conshdlrdata->currscore;
2794}
2795
2797 GCG* gcg
2798 )
2799{
2800 SCIP_CONSHDLRDATA* conshdlrdata;
2801 int i;
2802
2803 conshdlrdata = getConshdlrdata(gcg);
2804 assert(conshdlrdata != NULL);
2805
2806 char* shortname = GCGgetCurrentScoreShortname(gcg);
2807
2808 for( i = 0; i < conshdlrdata->nscores; ++i )
2809 {
2810 GCG_SCORE* score;
2811 score = conshdlrdata->scores[i];
2812 assert(score != NULL);
2813 if( strcmp(score->shortname, shortname) == 0 )
2814 {
2815 return score;
2816 }
2817 }
2818
2819 return NULL;
2820}
2821
2823 GCG* gcg,
2824 const char* name,
2825 const char* shortname,
2826 const char* description,
2827 GCG_SCOREDATA* scoredata,
2828 GCG_DECL_SCOREFREE ((*scorefree)),
2829 GCG_DECL_SCORECALC ((*scorecalc))
2830 )
2831{
2832 SCIP_CONSHDLRDATA* conshdlrdata;
2833 GCG_SCORE* score = NULL;
2835
2836 assert(scip != NULL);
2837 assert(name != NULL);
2838 assert(shortname != NULL);
2839 assert(description != NULL);
2840
2841 conshdlrdata = getConshdlrdata(gcg);
2842
2844 assert(score != NULL);
2845
2846 SCIPdebugMessage("Adding score %i: %s\n", conshdlrdata->nscores+1, name);
2847
2848 SCIP_ALLOC( BMSduplicateMemoryArray(&score->name, name, strlen(name)+1) );
2849 SCIP_ALLOC( BMSduplicateMemoryArray(&score->shortname, shortname, strlen(shortname)+1) );
2850 SCIP_ALLOC( BMSduplicateMemoryArray(&score->description, description, strlen(description)+1) );
2851 score->scoredata = scoredata;
2852
2853 score->scorefree = scorefree;
2854 score->scorecalc = scorecalc;
2855
2856 SCIP_CALL( SCIPreallocMemoryArray(scip, &conshdlrdata->scores, (size_t)conshdlrdata->nscores+1) );
2857
2858 conshdlrdata->scores[conshdlrdata->nscores] = score;
2859 conshdlrdata->nscores = conshdlrdata->nscores+1;
2860
2861 return SCIP_OKAY;
2862}
2863
2865 GCG* gcg
2866 )
2867{
2868 int ndetectors;
2869 int i;
2871 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2872 assert(conshdlrdata != NULL);
2873
2874 ndetectors = conshdlrdata->ndetectors;
2875
2876 SCIPdialogMessage(scip, NULL, " detector char priority enabled description\n");
2877 SCIPdialogMessage(scip, NULL, " -------------- ---- -------- ------- -----------\n");
2878
2879 for( i = 0; i < ndetectors; ++i )
2880 {
2881 SCIPdialogMessage(scip, NULL, " %-20s ", conshdlrdata->detectors[i]->name);
2882 if( strlen(conshdlrdata->detectors[i]->name) > 20 )
2883 SCIPdialogMessage(scip, NULL, "\n %20s ", "-->");
2884 SCIPdialogMessage(scip, NULL, "%c ", conshdlrdata->detectors[i]->decchar);
2885 SCIPdialogMessage(scip, NULL, "%8d ", conshdlrdata->detectors[i]->priority);
2886 SCIPdialogMessage(scip, NULL, "%7s ", conshdlrdata->detectors[i]->enabled ? "TRUE" : "FALSE");
2887 SCIPdialogMessage(scip, NULL, "%s", conshdlrdata->detectors[i]->description);
2888 SCIPdialogMessage(scip, NULL, "\n");
2889 }
2890}
2891
2892
2894 GCG* gcg,
2895 char* directory,
2896 char* extension,
2897 SCIP_Bool original,
2898 SCIP_Bool presolved
2899 )
2900{
2901 char outname[SCIP_MAXSTRLEN];
2902 char tempstring[SCIP_MAXSTRLEN];
2903 int i;
2904
2905 int maxtowrite;
2906 int nwritten;
2908
2909 assert(extension != NULL);
2910
2911 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2912 assert(conshdlrdata != NULL);
2913
2914 maxtowrite = -1;
2915 nwritten = 0;
2916
2917 if( presolved && conshdlrdata->detprobdatapres != NULL && conshdlrdata->detprobdatapres->getNFinishedPartialdecs() == 0 )
2918 {
2919 SCIPwarningMessage(scip, "No decomposition available.\n");
2920 return SCIP_OKAY;
2921 }
2922
2923 SCIPgetIntParam(scip, "visual/nmaxdecompstowrite", &maxtowrite );
2924
2925 /* write all finished partialdecs */
2926 std::vector<PARTIALDECOMP*> partialdecs;
2927 getFinishedPartialdecs(gcg, partialdecs);
2928 for( i = 0; i < (int) partialdecs.size(); i++)
2929 {
2930 PARTIALDECOMP* partialdec = partialdecs.at(i);
2931
2932 /* get filename */
2933 GCGgetVisualizationFilename(gcg, partialdec, extension, tempstring);
2934 if( directory != NULL )
2935 {
2936 (void) SCIPsnprintf(outname, SCIP_MAXSTRLEN, "%s/%s.%s", directory, tempstring, extension);
2937 }
2938 else
2939 {
2940 (void) SCIPsnprintf(outname, SCIP_MAXSTRLEN, "%s.%s", tempstring, extension);
2941 }
2942
2943 /* mark partialdec */
2944 conshdlrdata->partialdectowrite = partialdec;
2945
2946 /* these functions write the marked partialdec */
2947 if( partialdec->isAssignedToOrigProb() )
2948 SCIP_CALL_QUIET( SCIPwriteOrigProblem(scip, outname, extension, FALSE) );
2949 else
2950 SCIP_CALL( SCIPwriteTransProblem(scip, outname, extension, FALSE) );
2951
2952 ++nwritten;
2953 conshdlrdata->partialdectowrite = NULL;
2954
2955 /* stop if max is reached */
2956 if( maxtowrite != -1 && nwritten >= maxtowrite )
2957 break;
2958 }
2959
2960 return SCIP_OKAY;
2961}
2962
2963
2965 GCG* gcg,
2966 char* directory,
2967 char* extension
2968 )
2969{
2970 char outname[SCIP_MAXSTRLEN];
2971 char tempstring[SCIP_MAXSTRLEN];
2973
2974 assert(extension != NULL);
2975
2976 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
2977 assert(conshdlrdata != NULL);
2978
2979 if( conshdlrdata->partialdecs->empty() )
2980 {
2981 SCIPwarningMessage(scip, "No decomposition available.\n");
2982 return SCIP_OKAY;
2983 }
2984
2985 std::vector<PARTIALDECOMP*> selectedpartialdecs;
2986 getSelectedPartialdecs(gcg, selectedpartialdecs);
2987 if( selectedpartialdecs.empty() )
2988 {
2989 SCIPwarningMessage(scip, "No decomposition selected.\n");
2990 return SCIP_OKAY;
2991 }
2992
2993 for(auto & partialdec : selectedpartialdecs)
2994 {
2995 GCGgetVisualizationFilename(gcg, partialdec, extension, tempstring);
2996 if( directory != NULL )
2997 {
2998 (void) SCIPsnprintf(outname, SCIP_MAXSTRLEN, "%s/%s.%s", directory, tempstring, extension);
2999 }
3000 else
3001 {
3002 (void) SCIPsnprintf(outname, SCIP_MAXSTRLEN, "%s.%s", tempstring, extension);
3003 }
3004
3005 conshdlrdata->partialdectowrite = partialdec;
3006
3007 if ( partialdec->isAssignedToOrigProb() )
3008 SCIP_CALL_QUIET( SCIPwriteOrigProblem(scip, outname, extension, FALSE) );
3009 else
3010 SCIP_CALL_QUIET( SCIPwriteTransProblem(scip, outname, extension, FALSE) );
3011
3012 conshdlrdata->partialdectowrite = NULL;
3013 }
3014
3015 return SCIP_OKAY;
3016}
3017
3018
3020 GCG* gcg,
3021 SCIP_Bool presolved,
3022 PARTIALDECOMP_C** partialdecomp
3023 )
3024{
3025 PARTIALDECOMP* partialdec = new PARTIALDECOMP(gcg, !presolved);
3026 partialdec->setNBlocks(0);
3027 partialdec->assignOpenConssToMaster();
3028 partialdec->prepare();
3029 *partialdecomp = reinterpret_cast<PARTIALDECOMP_C*>(partialdec);
3030 SCIP_CALL( addPartialdec(gcg, partialdec) );
3031 return SCIP_OKAY;
3032}
3033
3034
3036 GCG* gcg,
3037 SCIP_Bool origprob,
3038 int candidate
3039 )
3040{
3041 gcg::DETPROBDATA* detprobdata;
3042 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3043 assert(conshdlrdata != NULL);
3044
3045 detprobdata = origprob ? conshdlrdata->detprobdataorig : conshdlrdata->detprobdatapres;
3046
3047 if( candidate > 1 )
3048 {
3049 bool alreadyIn = false;
3050 for( size_t i = 0; i < detprobdata->candidatesNBlocks.size(); ++ i )
3051 {
3052 if( detprobdata->candidatesNBlocks[i].first == candidate )
3053 {
3054 alreadyIn = true;
3055 ++detprobdata->candidatesNBlocks[i].second;
3056 break;
3057 }
3058 }
3059 if( !alreadyIn )
3060 {
3061 SCIPverbMessage(GCGgetOrigprob(gcg), SCIP_VERBLEVEL_FULL, NULL, "added block number candidate: %d \n", candidate );
3062 detprobdata->candidatesNBlocks.emplace_back(candidate, 1);
3063 }
3064 }
3065}
3066
3067
3069 GCG* gcg,
3070 SCIP_Bool presolved
3071 )
3072{
3073 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3074 assert(conshdlrdata != NULL);
3075
3076 DETPROBDATA* detprobdata;
3077 // check if detection took place (this might be used in e.g. write problem)
3078 if(presolved)
3079 {
3081 resetDetprobdata(gcg, false);
3082 detprobdata = conshdlrdata->detprobdatapres;
3083 }
3084 else
3085 {
3087 resetDetprobdata(gcg, true);
3088 detprobdata = conshdlrdata->detprobdataorig;
3089 }
3090
3091 assert(detprobdata != NULL);
3092
3093 PARTIALDECOMP* matrixpartialdec;
3094
3095 matrixpartialdec = new PARTIALDECOMP(gcg, !presolved);
3096 matrixpartialdec->setNBlocks(1);
3097
3098 for( int i = 0; i < detprobdata->getNConss(); ++i )
3099 matrixpartialdec->fixConsToBlock(i,0);
3100
3101 for( int i = 0; i < detprobdata->getNVars(); ++i )
3102 matrixpartialdec->fixVarToBlock(i,0);
3103
3104 matrixpartialdec->sort();
3105
3106 detprobdata->addPartialdecToFinishedUnchecked(matrixpartialdec);
3107
3108 return matrixpartialdec->getID();
3109}
3110
3111
3113 GCG* gcg,
3114 GCG_DECOMP* decomp
3115 )
3116{
3117 PARTIALDECOMP* partialdec;
3119
3121 {
3122 SCIPerrorMessage("Problem is not presolved yet.");
3123 return SCIP_ERROR;
3124 }
3125
3126 SCIP_CALL( createPartialdecFromDecomp(gcg, decomp, &partialdec) );
3128
3129 return SCIP_OKAY;
3130}
3131
3132
3134 GCG* gcg,
3135 PARTIALDECOMP* partialdec
3136 )
3137{
3139}
3140
3141
3143 GCG* gcg,
3144 gcg::PARTIALDECOMP* partialdec,
3145 SCIP_Bool addpartialdec
3146 )
3147{
3148 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3150 assert(conshdlrdata != NULL);
3151 assert(partialdec != NULL);
3152
3153 partialdec->considerImplicits();
3154
3155 if( partialdec->shouldCompletedByConsToMaster() )
3156 {
3157 if( !partialdec->isComplete() )
3158 {
3159 if( addpartialdec )
3160 {
3161 gcg::PARTIALDECOMP* partial = new gcg::PARTIALDECOMP(partialdec);
3164 }
3165
3166 auto& openconss = partialdec->getOpenconss();
3167 for( auto itr = openconss.cbegin(); itr != openconss.cend(); )
3168 {
3169 itr = partialdec->fixConsToMaster(itr);
3170 }
3171 assert(partialdec->getUsergiven() == USERGIVEN::COMPLETED_CONSTOMASTER);
3172 }
3173 else
3174 {
3175 partialdec->setUsergiven(USERGIVEN::COMPLETE);
3176 }
3177 }
3178 else
3179 {
3180 if( partialdec->isComplete() )
3181 partialdec->setUsergiven(USERGIVEN::COMPLETE);
3182 else
3183 partialdec->setUsergiven(USERGIVEN::PARTIAL);
3184 }
3185
3186 partialdec->prepare();
3187
3188#ifndef NDEBUG
3189 if( partialdec->getUsergiven() == USERGIVEN::COMPLETE || partialdec->getUsergiven() == USERGIVEN::COMPLETED_CONSTOMASTER )
3190 assert( partialdec->isComplete() );
3191#endif
3192
3193 addPartialdec(gcg, partialdec);
3194
3195 if( partialdec->isComplete() )
3196 {
3197 /* if detprobdata for presolved problem already exist try to translate partialdec */
3198 if ( conshdlrdata->detprobdatapres != NULL && partialdec->isAssignedToOrigProb())
3199 {
3200 int nmaxpresolrounds;
3201 std::vector<PARTIALDECOMP*> partialdectotranslate;
3202 partialdectotranslate.push_back(partialdec);
3203 SCIPgetIntParam(scip, "presolving/maxrounds", &nmaxpresolrounds);
3204 std::vector<PARTIALDECOMP*> newpartialdecs = conshdlrdata->detprobdatapres->translatePartialdecs(conshdlrdata->detprobdataorig, partialdectotranslate, nmaxpresolrounds == 0);
3205 if( !newpartialdecs.empty() )
3206 {
3207 addPartialdec(gcg, newpartialdecs[0]);
3208 }
3209 }
3210 }
3211
3212 /* set statistics */
3213 int nvarstoblock = 0;
3214 int nconsstoblock = 0;
3215
3216 for ( int b = 0; b < partialdec->getNBlocks(); ++b )
3217 {
3218 nvarstoblock += partialdec->getNVarsForBlock(b);
3219 nconsstoblock += partialdec->getNConssForBlock(b);
3220 }
3221
3222 char const* usergiveninfo;
3223 char const* presolvedinfo;
3224
3225 if( partialdec->getUsergiven() == USERGIVEN::PARTIAL )
3226 usergiveninfo = "partial";
3227 if( partialdec->getUsergiven() == USERGIVEN::COMPLETE )
3228 usergiveninfo = "complete";
3229 if( partialdec->getUsergiven() == USERGIVEN::COMPLETED_CONSTOMASTER )
3230 usergiveninfo = "complete";
3231 if( partialdec->isAssignedToOrigProb() )
3232 presolvedinfo = "original";
3233 else presolvedinfo = "presolved";
3234
3235 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " added %s decomp for %s problem with %d blocks and %d masterconss, %d linkingvars, "
3236 "%d mastervars, and max white score of %s %f \n", usergiveninfo, presolvedinfo,
3237 partialdec->getNBlocks(), partialdec->getNMasterconss(),
3238 partialdec->getNLinkingvars(), partialdec->getNMastervars(), (partialdec->isComplete() ? " " : " at best "),
3239 partialdec->getScore(GCGconshdlrDecompFindScore(gcg, "max white")) );
3240
3241 return SCIP_OKAY;
3242}
3243
3244
3246 GCG* gcg
3247 )
3248{
3249 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3250 return conshdlrdata->scoreclock;
3251}
3252
3253
3255 GCG* gcg
3256)
3257{
3259 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3260 return SCIPgetClockTime(scip, conshdlrdata->scoreclock);
3261}
3262
3263
3265 GCG* gcg,
3266 int candidate
3267 )
3268{
3270 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3271
3272 // make sure there is a problem
3274 {
3276 "Please add a problem before adding block candidates.\n");
3277 return;
3278 }
3279
3280 conshdlrdata->userblocknrcandidates->push_back(candidate);
3281
3282 SCIPverbMessage(scip, SCIP_VERBLEVEL_DIALOG, NULL, "added user block number candidate: %d \n", candidate );
3283}
3284
3285
3287 SCIP* scip,
3288 PARTIALDECOMP_C* partialdecomp,
3289 int probnr1,
3290 int probnr2,
3291 SCIP_Bool* identical
3292 )
3293{
3294 gcg::PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
3295
3296 assert(partialdec != NULL);
3297 assert(partialdec->isComplete());
3298
3299 if( !partialdec->aggInfoCalculated() )
3300 {
3301 SCIPdebugMessage("calc aggregation information for partialdec!\n");
3302 // ignore limits of detection since we do this only for this specific partialdec
3303 partialdec->calcAggregationInformation(true);
3304 }
3305
3306 if( partialdec->getEqClassForBlock(probnr1) == partialdec->getEqClassForBlock(probnr2) )
3307 *identical = TRUE;
3308 else
3309 *identical = FALSE;
3310
3311 SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, " block %d and block %d are represented by %d and %d hence they are identical=%d.\n", probnr1, probnr2,
3312 partialdec->getEqClassForBlock(probnr1),
3313 partialdec->getEqClassForBlock(probnr2), *identical );
3314
3315 return SCIP_OKAY;
3316}
3317
3318
3320 GCG* gcg,
3321 SCIP_Bool transformed
3322 )
3323{
3325 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3326 gcg::DETPROBDATA* detprobdata = (transformed ? conshdlrdata->detprobdatapres : conshdlrdata->detprobdataorig );
3327 /* strategy: for every subset of constraint classes and variable classes calculate gcd (greatest common divisors)
3328 * of the corresponding number of constraints/variables assigned to this class */
3329
3330 SCIP_CLOCK* nblockcandnclock;
3331 SCIPcreateClock( scip, & nblockcandnclock );
3332 SCIPstartClock( scip, nblockcandnclock );
3333
3334 /* if distribution of classes exceeds this number it is skipped */
3335 int maximumnclasses;
3336 SCIP_Bool medianvarspercons;
3337
3338 /* used for nvars / medianofnvars per conss */
3339 std::vector<int> nvarspercons(0);
3340 std::list<int>::iterator iter;
3341 int candidate = -1;
3342
3343 medianvarspercons = conshdlrdata->blocknumbercandsmedianvarspercons;
3344 maximumnclasses = conshdlrdata->maxnclassesfornblockcandidates;
3345
3346 /* firstly, iterate over all conspartitions */
3347 for( auto partition : detprobdata->conspartitioncollection )
3348 {
3349 /* check if there are too many classes in this distribution and skip it if so */
3350 if( partition->getNClasses() > maximumnclasses )
3351 {
3352 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " the current consclass distribution includes %d classes but only %d are allowed for GCGconshdlrDecompCalcCandidatesNBlocks()\n", partition->getNClasses(), maximumnclasses );
3353 continue;
3354 }
3355
3356 /* get necessary data of current partition */
3357 std::vector<std::vector<int>> subsetsOfConstypes = partition->getAllSubsets(true, true, true );
3358 std::vector<int> nConssOfClasses = partition->getNConssOfClasses();
3359
3360 /* start with the cardinalities of the consclasses as candidates */
3361 for( size_t i = 0; i < nConssOfClasses.size(); ++ i )
3362 {
3363 GCGconshdlrDecompAddCandidatesNBlocks(gcg, detprobdata->isAssignedToOrigProb(), nConssOfClasses[i]);
3364 }
3365
3366 /* continue with gcd of all cardinalities in this subset */
3367 for( size_t subset = 0; subset < subsetsOfConstypes.size(); ++ subset )
3368 {
3369 int greatestCD = 1;
3370
3371 if( subsetsOfConstypes[subset].empty() || subsetsOfConstypes[subset].size() == 1 )
3372 continue;
3373
3374 greatestCD = gcd( nConssOfClasses[subsetsOfConstypes[subset][0]], nConssOfClasses[subsetsOfConstypes[subset][1]] );
3375
3376 for( size_t i = 2; i < subsetsOfConstypes[subset].size(); ++ i )
3377 {
3378 greatestCD = gcd( greatestCD, nConssOfClasses[subsetsOfConstypes[subset][i]] );
3379 }
3380
3382 }
3383 }
3384
3385 /* secondly, iterate over all varpartitions */
3386 for( auto partition : detprobdata->varpartitioncollection )
3387 {
3388 /* check if there are too many classes in this distribution and skip it if so */
3389 if( partition->getNClasses() > maximumnclasses )
3390 {
3391 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " the current varclass distribution includes %d classes but only %d are allowed for GCGconshdlrDecompCalcCandidatesNBlocks()\n", partition->getNClasses(), maximumnclasses );
3392 continue;
3393 }
3394
3395 /* get necessary data of current partition */
3396 std::vector<std::vector<int>> subsetsOfVartypes = partition->getAllSubsets(true, true, true, true );
3397 std::vector<int> nVarsOfClasses = partition->getNVarsOfClasses();
3398
3399 /* start with the cardinalities of the varclasses as candidates */
3400 for( int nVarsOfClasse : nVarsOfClasses )
3401 {
3402 GCGconshdlrDecompAddCandidatesNBlocks(gcg, detprobdata->isAssignedToOrigProb(), nVarsOfClasse);
3403 }
3404
3405 /* continue with gcd of all cardinalities in this subset */
3406 for(auto& subsetsOfVartype : subsetsOfVartypes)
3407 {
3408 int greatestCD = 1;
3409
3410 if( subsetsOfVartype.empty() || subsetsOfVartype.size() == 1 )
3411 continue;
3412
3413 greatestCD = gcd( nVarsOfClasses[subsetsOfVartype[0]], nVarsOfClasses[subsetsOfVartype[1]] );
3414
3415 for( size_t i = 2; i < subsetsOfVartype.size(); ++ i )
3416 {
3417 greatestCD = gcd( greatestCD, nVarsOfClasses[subsetsOfVartype[i]] );
3418 }
3419
3421 }
3422 }
3423
3424 /* block number candidate could be nvars / median of nvarsinconss only calculate if desired*/
3425 if( medianvarspercons )
3426 {
3427 for( int c = 0; c < detprobdata->getNConss(); ++c )
3428 {
3429 nvarspercons.push_back( detprobdata->getNVarsForCons(c) );
3430 }
3431 std::sort(nvarspercons.begin(), nvarspercons.end() );
3432 candidate = (int) detprobdata->getNVars() / nvarspercons[(int)detprobdata->getNConss()/2];
3433
3435 }
3436
3437 SCIPstopClock( scip, nblockcandnclock );
3438 detprobdata->nblockscandidatescalctime = SCIPgetClockTime( scip, nblockcandnclock );
3439 SCIPfreeClock( scip, & nblockcandnclock );
3440}
3441
3442
3444 GCG* gcg /* SCIP data structure */
3445 )
3446{
3447 int i;
3449 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3450 assert(conshdlrdata != NULL);
3451
3452 /* check whether the predecessors of all finished partialdecs in both detprobdatas can be found */
3453 if( conshdlrdata->detprobdatapres != NULL)
3454 {
3455 for( i = 0; i < conshdlrdata->detprobdatapres->getNFinishedPartialdecs(); ++i )
3456 {
3457 PARTIALDECOMP* partialdec = conshdlrdata->detprobdatapres->getFinishedPartialdec( i );
3458
3459 for( int j = 0; j < partialdec->getNAncestors(); ++j )
3460 {
3461 int id = partialdec->getAncestorID( j );
3463 {
3464 SCIPwarningMessage(scip, "Warning: presolved partialdec %d has an ancestor (id: %d) that is not found! \n", partialdec->getID(), id );
3465 return FALSE;
3466 }
3467 }
3468 }
3469 }
3470
3471 if( conshdlrdata->detprobdataorig != NULL )
3472 {
3473 for( i = 0; i < conshdlrdata->detprobdataorig->getNFinishedPartialdecs(); ++i )
3474 {
3475 PARTIALDECOMP* partialdec = conshdlrdata->detprobdataorig->getFinishedPartialdec( i );
3476
3477 for( int j = 0; j < partialdec->getNAncestors(); ++j )
3478 {
3479 int id = partialdec->getAncestorID( j );
3481 {
3482 SCIPwarningMessage(scip, "Warning: orig partialdec %d has an ancestor (id: %d) that is not found! \n", partialdec->getID(), id );
3483 return FALSE;
3484 }
3485 }
3486 }
3487 }
3488
3489 return TRUE;
3490}
3491
3492
3494 GCG* gcg,
3495 std::vector<std::pair<gcg::PARTIALDECOMP*, SCIP_Real> >& candidates,
3496 SCIP_Bool original,
3497 SCIP_Bool printwarnings
3498 )
3499{
3501 std::vector<PARTIALDECOMP*>::iterator partialdeciter;
3502 std::vector<PARTIALDECOMP*>::iterator partialdeciterend;
3503
3504 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3505 if( conshdlrdata == NULL )
3506 {
3507 SCIPerrorMessage("Decomp constraint handler is not included, cannot manage decompositions!\n");
3508 return SCIP_ERROR;
3509 }
3510
3511 if( (!original && conshdlrdata->detprobdatapres == NULL) || (original && conshdlrdata->detprobdataorig == NULL) )
3512 {
3513 return SCIP_OKAY;
3514 }
3515
3516 SCIPdebugMessage("Starting decomposition candidate choosing \n");
3517
3519
3520 std::vector<PARTIALDECOMP*> selectedpartialdecs;
3521 getSelectedPartialdecs(gcg, selectedpartialdecs);
3522
3523 if( selectedpartialdecs.empty() )
3524 {
3525 SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "currently no decomposition is selected, hence every known decomposition is considered: \n");
3526 if( original )
3527 {
3528 selectedpartialdecs = conshdlrdata->detprobdataorig->getFinishedPartialdecs();
3529 }
3530 else
3531 {
3532 selectedpartialdecs = conshdlrdata->detprobdatapres->getFinishedPartialdecs();
3533 }
3534 SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "number of considered decompositions: %ld \n", selectedpartialdecs.size() );
3535 }
3536
3537 partialdeciter = selectedpartialdecs.begin();
3538 partialdeciterend = selectedpartialdecs.end();
3539
3540 /* get decomp candidates and calculate corresponding score */
3541 for( ; partialdeciter != partialdeciterend; ++partialdeciter )
3542 {
3543 PARTIALDECOMP* partialdec = *partialdeciter;
3544 if( !original && partialdec->isAssignedToOrigProb() )
3545 {
3547 assert(partialdec != NULL);
3548 if( !partialdec->isComplete() )
3549 {
3550 if( printwarnings )
3551 {
3552 SCIPwarningMessage(scip, "A selected decomposition (id=%d) of the orig. problem is ignored since its translation is incomplete.\n", partialdec->getID());
3553 }
3554 continue;
3555 }
3556 }
3557
3558 assert(partialdec != NULL);
3559 if( partialdec->isComplete() )
3560 {
3561 candidates.emplace_back(partialdec, partialdec->getScore(GCGgetCurrentScore(gcg)));
3562 }
3563 else if( printwarnings )
3564 {
3565 SCIPwarningMessage(scip, "A selected decomposition (id=%d) is ignored since it is incomplete.\n", partialdec->getID());
3566 }
3567 }
3568
3569 /* sort decomp candidates according to score */
3570 std::sort( candidates.begin(), candidates.end(), sort_pred() );
3571
3572 return SCIP_OKAY;
3573}
3574
3575
3577 GCG* gcg,
3578 SCIP_Bool transformed
3579 )
3580{
3581 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3583
3584 gcg::DETPROBDATA* detprobdata;
3585 if (transformed) {
3586 detprobdata = conshdlrdata->detprobdatapres;
3587 } else{
3588 detprobdata = conshdlrdata->detprobdataorig;
3589 }
3590
3591 // Start clock
3592 SCIP_CLOCK* classificationclock;
3593 SCIPcreateClock( scip, & classificationclock );
3594 SCIP_CALL( SCIPstartClock( scip, classificationclock ) );
3595
3596 // Cons classifiers
3597 for(int i = 0; i < conshdlrdata->nconsclassifiers; i++) {
3598 GCG_CONSCLASSIFIER *classifier;
3599 SCIP_Bool enabled;
3600 classifier = conshdlrdata->consclassifiers[i];
3601
3602 char setting[SCIP_MAXSTRLEN];
3603 (void) SCIPsnprintf(setting, SCIP_MAXSTRLEN, "detection/classification/consclassifier/%s/enabled", classifier->name);
3604
3605 SCIPgetBoolParam( scip, setting, &enabled );
3606 if ( enabled ) {
3607 classifier->classify(conshdlrdata->gcg, classifier, transformed);
3608 }
3609 }
3610
3611 // Var classifiers
3612 for(int i = 0; i < conshdlrdata->nvarclassifiers; i++) {
3613 GCG_VARCLASSIFIER *classifier;
3614 SCIP_Bool enabled;
3615 classifier = conshdlrdata->varclassifiers[i];
3616
3617 char setting[SCIP_MAXSTRLEN];
3618 (void) SCIPsnprintf(setting, SCIP_MAXSTRLEN, "detection/classification/varclassifier/%s/enabled", classifier->name);
3619
3620 SCIPgetBoolParam( scip, setting, &enabled );
3621 if ( enabled ) {
3622 classifier->classify(conshdlrdata->gcg, classifier, transformed);
3623 }
3624 }
3625
3626 // Reduce number of classes
3627 reduceConsclasses(gcg, detprobdata);
3628 reduceVarclasses(gcg, detprobdata);
3629
3630 // Stop clock
3631 SCIP_CALL( SCIPstopClock( scip, classificationclock ) );
3632 detprobdata->classificationtime += SCIPgetClockTime( scip, classificationclock );
3633 SCIPfreeClock( scip, & classificationclock );
3634
3635 return SCIP_OKAY;
3636}
3637
3638
3640 SCIP* scip,
3641 SCIP_HASHMAP** hashorig2pricingvar,
3642 PARTIALDECOMP_C* partialdecomp,
3643 int probnr1,
3644 int probnr2,
3645 SCIP* scip1,
3646 SCIP* scip2,
3647 SCIP_HASHMAP* varmap
3648 )
3649{
3650 gcg::PARTIALDECOMP* partialdec;
3651 gcg::DETPROBDATA* currdetprobdata;
3652
3653 int blockid1;
3654 int blockid2;
3655 int representative;
3656 int repid1;
3657 int repid2;
3658 int nblocksforrep;
3659 std::vector<int> pidtopid;
3660
3661 repid1 = -1;
3662 repid2 = -1;
3663
3664 partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
3665 assert(partialdec != NULL);
3666 assert(partialdec->isComplete());
3667 currdetprobdata = partialdec->getDetprobdata();
3668
3669 if( probnr1 > probnr2 )
3670 {
3671 blockid1 = probnr2;
3672 blockid2 = probnr1;
3673 }
3674 else
3675 {
3676 blockid1 = probnr1;
3677 blockid2 = probnr2;
3678 }
3679
3680 representative = partialdec->getEqClassForBlock(blockid1);
3681 assert( representative == partialdec->getEqClassForBlock(blockid2) );
3682 nblocksforrep = (int) partialdec->getBlocksForEqClass(representative).size();
3683
3684 /* find index in representatives */
3685 for( int i = 0; i < nblocksforrep; ++i )
3686 {
3687 if( partialdec->getBlocksForEqClass(representative)[i] == blockid1 )
3688 repid1 = i;
3689 if( partialdec->getBlocksForEqClass(representative)[i] == blockid2 )
3690 {
3691 repid2 = i;
3692 break;
3693 }
3694 }
3695
3696 /* blockid1 should be the representative */
3697 if( repid1 != 0 )
3698 {
3699 SCIPhashmapFree(&varmap);
3700 varmap = NULL;
3701 SCIPwarningMessage(scip, "blockid1 should be the representative (hence has id=0 in reptoblocksarray but in fact has %d) \n", repid1);
3702 return SCIP_OKAY;
3703 }
3704
3705 pidtopid = partialdec->getRepVarmap(representative, repid2);
3706
3707 for( int v = 0; v < SCIPgetNVars(scip2); ++v )
3708 {
3709 SCIP_VAR* var1;
3710 SCIP_VAR* var2;
3711 SCIP_VAR* var1orig;
3712 SCIP_VAR* var2orig;
3713 int var1origid;
3714 int var2origid;
3715 int var1originblockid;
3716 int var2originblockid;
3717
3718 var2 = SCIPgetVars(scip2)[v];
3719 assert(var2 != NULL);
3720 var2orig = GCGpricingVarGetOriginalVar(var2);
3721 assert(var2orig!=NULL);
3722 var2origid = currdetprobdata->getIndexForVar(var2orig) ;
3723 assert(var2origid>=0);
3724 var2originblockid = partialdec->getVarProbindexForBlock(var2origid, blockid2) ;
3725 assert(var2originblockid >= 0);
3726 var1originblockid = pidtopid[var2originblockid];
3727 assert(var1originblockid>=0);
3728 var1origid = partialdec->getVarsForBlock(blockid1)[var1originblockid];
3729 assert(var1origid>=0);
3730 var1orig = currdetprobdata->getVar(var1origid) ;
3731 assert(var1orig != NULL);
3732 var1 = (SCIP_VAR*) SCIPhashmapGetImage(hashorig2pricingvar[blockid1], (void*) var1orig ) ;
3733 assert(var1 != NULL);
3734
3735 SCIPhashmapInsert(varmap, (void*) var2, (void*) var1);
3736 }
3737
3738 return SCIP_OKAY;
3739}
3740
3741
3743 GCG* gcg
3744 )
3745{
3746 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3747 assert(conshdlrdata != NULL);
3748
3749 --conshdlrdata->ncallscreatedecomp;
3750
3751 return conshdlrdata->ncallscreatedecomp;
3752}
3753
3754
3756 GCG* gcg,
3757 SCIP_Bool original
3758 )
3759{
3760 SCIP_CONSHDLRDATA *conshdlrdata = getConshdlrdata(gcg);
3761
3762 for( int i = (int) conshdlrdata->partialdecs->size() - 1; i >= 0; --i)
3763 {
3764 PARTIALDECOMP* partialdec = (*conshdlrdata->partialdecs)[i];
3765 if( partialdec->isAssignedToOrigProb() == (bool) original )
3766 {
3767 // ~PARTIALDECOMP will clean up references
3768 delete partialdec;
3769 }
3770 }
3771}
3772
3773
3775 GCG* gcg,
3776 PARTIALDECOMP* partialdec
3777 )
3778{
3779 int i = 0;
3780 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3781
3782 assert(conshdlrdata != NULL);
3783 assert(partialdec != NULL);
3784
3785 int id = partialdec->getID();
3786
3787 // remove partialdec from list
3788 for(i = (int) conshdlrdata->partialdecs->size() - 1; i >= 0 ; i--)
3789 {
3790 // as registering checks for dublicates,
3791 // assumption that the partialdecs are unique in the list
3792 if(partialdec == conshdlrdata->partialdecs->at(i))
3793 {
3794 // delete item at index i
3795 conshdlrdata->partialdecs->erase(conshdlrdata->partialdecs->begin() + i);
3796 break;
3797 }
3798 }
3799
3800 conshdlrdata->partialdecsbyid->erase(id);
3801
3802 // remove partialdec from ancestors of all other partialdecs to avoid NULL pointers
3803 for(i = 0; i < (int) conshdlrdata->partialdecs->size(); i++)
3804 {
3805 conshdlrdata->partialdecs->at(i)->removeAncestorID(id);
3806 }
3807}
3808
3809
3811 GCG* gcg
3812 )
3813{
3814 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3815 assert(conshdlrdata != NULL);
3816
3817 /* remove the presolved detprobdata */
3818 delete conshdlrdata->detprobdatapres;
3819 conshdlrdata->detprobdatapres = NULL;
3820
3821 /* if parameter is set, free orig detprobdata */
3822 if( conshdlrdata->freeorig )
3823 {
3824 delete conshdlrdata->detprobdataorig;
3825 conshdlrdata->detprobdataorig = NULL;
3826 conshdlrdata->hasrunoriginal = FALSE;
3827 }
3828}
3829
3830
3832 GCG* gcg,
3833 SCIP_Bool free
3834 )
3835{
3836 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3837 assert(conshdlrdata != NULL);
3838
3839 conshdlrdata->freeorig = free;
3840}
3841
3842
3844 GCG* gcg,
3845 int index
3846 )
3847{
3848 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3849 assert(conshdlrdata != NULL);
3850
3851 assert(index < (int) conshdlrdata->userblocknrcandidates->size());
3852 return conshdlrdata->userblocknrcandidates->at(index);
3853}
3854
3855
3857 GCG* gcg
3858 )
3859{
3860 SCIP_Real totaltime;
3862 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3863 assert(conshdlrdata != NULL);
3864
3865 totaltime = SCIPgetClockTime(scip, conshdlrdata->completedetectionclock );
3866
3867 return totaltime;
3868}
3869
3870
3872 GCG* gcg
3873 )
3874{
3875 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3877 assert(conshdlrdata != NULL);
3878 int decompcounter = 0;
3879 int i;
3880
3881 for( i = 0; i < conshdlrdata->ndecomps; ++i )
3882 {
3883 GCGdecompFree(gcg, &conshdlrdata->decomps[conshdlrdata->ndecomps - i - 1]);
3884 }
3885
3886 SCIPfreeBlockMemoryArray(scip, &conshdlrdata->decomps, conshdlrdata->ndecomps);
3887
3889
3890 conshdlrdata->ndecomps = GCGconshdlrDecompGetNDecomps(gcg);
3891
3893 for(i = 0; i < (int) conshdlrdata->partialdecs->size(); i++)
3894 {
3895 gcg::PARTIALDECOMP* partialdec = conshdlrdata->partialdecs->at(i);
3896 createDecompFromPartialdec(gcg, partialdec, &conshdlrdata->decomps[decompcounter] );
3897 ++decompcounter;
3898 }
3899
3900 return conshdlrdata->decomps;
3901}
3902
3903
3905 PARTIALDECOMP_C* partialdecomp
3906 )
3907{
3908 char buffer[SCIP_MAXSTRLEN];
3909 /* get partialdec and returns its detector history */
3910 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
3911 assert(partialdec != NULL);
3912 partialdec->buildDecChainString(buffer);
3913 return std::string(buffer);
3914}
3915
3916
3918 GCG* gcg
3919 )
3920{
3921 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3922 assert(conshdlrdata != NULL);
3923
3924 return conshdlrdata->detectors;
3925}
3926
3927
3929 GCG* gcg
3930 )
3931{
3932 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3933 assert(conshdlrdata != NULL);
3934
3935 return conshdlrdata->scores;
3936
3937}
3938
3939
3941 GCG* gcg
3942 )
3943{
3944 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3945 assert(conshdlrdata != NULL);
3946
3947 return conshdlrdata->consclassifiers;
3948}
3949
3950
3952 GCG* gcg
3953 )
3954{
3955 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3956 assert(conshdlrdata != NULL);
3957
3958 return conshdlrdata->varclassifiers;
3959}
3960
3961
3963 GCG* gcg
3964 )
3965{
3966 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3967 assert(conshdlrdata != NULL);
3968
3970 resetDetprobdata(gcg, true);
3971
3972 return conshdlrdata->detprobdataorig;
3973}
3974
3975
3977 GCG* gcg
3978 )
3979{
3980 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
3981 assert(conshdlrdata != NULL);
3982
3984 resetDetprobdata(gcg, false);
3985
3986 return conshdlrdata->detprobdatapres;
3987}
3988
3989
3991 GCG* gcg,
3992 int** idlist,
3993 int* listlength
3994 )
3995{
3996 std::vector<PARTIALDECOMP*> partialdecs;
3997 getFinishedPartialdecs(gcg, partialdecs);
3998 partialdecVecToIdArray(partialdecs, idlist, listlength);
3999
4000 return SCIP_OKAY;
4001}
4002
4003
4005 GCG* gcg,
4006 int** idlist,
4007 int* listlength
4008 )
4009{
4010 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4011 assert( conshdlrdata != NULL );
4012 partialdecVecToIdArray(*conshdlrdata->partialdecs, idlist, listlength);
4013
4014 return SCIP_OKAY;
4015}
4016
4017
4019 GCG* gcg
4020 )
4021{
4022 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4023 assert(conshdlrdata != NULL);
4024
4025 return (int) conshdlrdata->userblocknrcandidates->size();
4026}
4027
4028
4030 PARTIALDECOMP_C* partialdecomp
4031 )
4032{
4033 /* get partialdec and returns the number of its blocks */
4034 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4035 assert(partialdec != NULL);
4036 return partialdec->getNBlocks();
4037}
4038
4039
4041 GCG* gcg
4042 )
4043{
4044 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4045 int ndecomps;
4046
4047 assert(conshdlrdata != NULL);
4048
4049 ndecomps = 0;
4050
4051 for(auto partialdec : *conshdlrdata->partialdecs)
4052 {
4053 if(partialdec->isComplete())
4054 ndecomps++;
4055 }
4056
4057 return ndecomps;
4058}
4059
4060
4062 GCG* gcg
4063 )
4064{
4065 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4066 assert(conshdlrdata != NULL);
4067
4068 return conshdlrdata->ndetectors;
4069}
4070
4072 GCG* gcg
4073 )
4074{
4075 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4076 assert(conshdlrdata != NULL);
4077
4078 return conshdlrdata->nconsclassifiers;
4079}
4080
4082 GCG* gcg
4083 )
4084{
4085 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4086 assert(conshdlrdata != NULL);
4087
4088 return conshdlrdata->nvarclassifiers;
4089}
4090
4092 GCG* gcg
4093 )
4094{
4095 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4096 assert(conshdlrdata != NULL);
4097
4098 return conshdlrdata->nscores;
4099}
4100
4101
4103 GCG* gcg
4104 )
4105{
4106 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4107 assert(conshdlrdata != NULL);
4108
4109 conshdlrdata->partialdeccounter = conshdlrdata->partialdeccounter + 1;
4110
4112
4113 return conshdlrdata->partialdeccounter;
4114}
4115
4116
4118 GCG* gcg,
4119 int id
4120 )
4121{
4122 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4123 assert(conshdlrdata != NULL);
4124
4125 // look for the partialdec and check whether it is complete
4126 auto itr = conshdlrdata->partialdecsbyid->find(id);
4127 if( itr != conshdlrdata->partialdecsbyid->end() && itr->second->isComplete() )
4128 {
4129 return itr->second->getDetprobdata()->getNConss();
4130 }
4131
4132 /* partialdec is not found hence we should not trust the isomorph information from detection */
4133 return -1;
4134}
4135
4136
4138 PARTIALDECOMP_C* partialdecomp
4139 )
4140{
4141 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4142 assert(partialdec != NULL);
4143 return partialdec->aggInfoCalculated();
4144}
4145
4146
4148 PARTIALDECOMP_C* partialdecomp,
4149 SCIP_Bool ignoreDetectionLimits
4150 )
4151{
4152 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4153 assert(partialdec != NULL);
4154 partialdec->calcAggregationInformation(ignoreDetectionLimits);
4155}
4156
4157
4159 PARTIALDECOMP_C* partialdecomp
4160 )
4161{
4162 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4163 assert(partialdec != NULL);
4164 return partialdec->getNEquivalenceClasses();
4165}
4166
4167
4169 PARTIALDECOMP_C* partialdecomp,
4170 int eqclass
4171 )
4172{
4173 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4174 assert(partialdec != NULL);
4175 return partialdec->getReprBlockForEqClass(eqclass);
4176}
4177
4178
4180 PARTIALDECOMP_C* partialdecomp,
4181 int eqclass
4182 )
4183{
4184 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4185 assert(partialdec != NULL);
4186 return partialdec->getBlocksForEqClass(eqclass).data();
4187}
4188
4189
4191 PARTIALDECOMP_C* partialdecomp,
4192 int eqclass
4193 )
4194{
4195 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4196 assert(partialdec != NULL);
4197 return (int)partialdec->getBlocksForEqClass(eqclass).size();
4198}
4199
4200
4202 PARTIALDECOMP_C* partialdecomp,
4203 int eqclass,
4204 int eqclassblock
4205 )
4206{
4207 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4208 assert(partialdec != NULL);
4209 return partialdec->getRepVarmap(eqclass, eqclassblock).data();
4210}
4211
4212
4214 PARTIALDECOMP_C* partialdecomp
4215 )
4216{
4217 /* get partialdec and returns the number of its linking vars */
4218 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4219 assert(partialdec != NULL);
4220 return partialdec->getNLinkingvars();
4221}
4222
4223
4225 PARTIALDECOMP_C* partialdecomp
4226 )
4227{
4228 /* get partialdec and returns the number of its master conss */
4229 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4230 assert(partialdec != NULL);
4231 return partialdec->getNMasterconss();
4232}
4233
4234
4236 PARTIALDECOMP_C* partialdecomp
4237 )
4238{
4239 /* get partialdec and returns the number of its master vars */
4240 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4241 assert(partialdec != NULL);
4242 return partialdec->getNMastervars();
4243}
4244
4245
4247 PARTIALDECOMP_C* partialdecomp
4248 )
4249{
4250 /* get partialdec and returns the number of its open conss */
4251 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4252 assert(partialdec != NULL);
4253 return partialdec->getNOpenconss();
4254}
4255
4256
4258 PARTIALDECOMP_C* partialdecomp
4259 )
4260{
4261 /* get partialdec and returns the number of its open vars */
4262 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4263 assert(partialdec != NULL);
4264 return partialdec->getNOpenvars();
4265}
4266
4267
4269 PARTIALDECOMP_C* partialdecomp,
4270 int block,
4271 int blockvarindex
4272 )
4273{
4274 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4275 assert(partialdec != NULL);
4276 return partialdec->getDetprobdata()->getVar(partialdec->getVarsForBlock(block)[blockvarindex]);
4277}
4278
4279
4281 PARTIALDECOMP_C* partialdecomp,
4282 int block
4283 )
4284{
4285 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4286 assert(partialdec != NULL);
4287 return partialdec->getNVarsForBlock(block);
4288}
4289
4290
4292 GCG* gcg
4293 )
4294{
4295 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4296 assert(conshdlrdata != NULL);
4297
4298 if( conshdlrdata->detprobdataorig == NULL )
4299 return 0;
4300
4301 return (int) conshdlrdata->detprobdataorig->getNFinishedPartialdecs();
4302}
4303
4304
4306 GCG* gcg
4307 )
4308{
4309 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4310 assert(conshdlrdata != NULL);
4311
4312 if( conshdlrdata->detprobdatapres == NULL )
4313 return 0;
4314
4315 return (int) conshdlrdata->detprobdatapres->getNFinishedPartialdecs();
4316}
4317
4318
4320 GCG* gcg
4321 )
4322{
4323 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4324 assert(conshdlrdata != NULL);
4325
4326 if( conshdlrdata->detprobdataorig == NULL )
4327 return 0;
4328
4329 return (int) conshdlrdata->detprobdataorig->getNOpenPartialdecs();
4330}
4331
4332
4334 GCG* gcg
4335 )
4336{
4337 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4338 assert(conshdlrdata != NULL);
4339
4340 if( conshdlrdata->detprobdatapres == NULL )
4341 return 0;
4342
4343 return (int) conshdlrdata->detprobdatapres->getNOpenPartialdecs();
4344}
4345
4346
4348 GCG* gcg
4349 )
4350{
4351 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4352 assert(conshdlrdata != NULL);
4353
4354 return (int) conshdlrdata->partialdecs->size();
4355}
4356
4357
4359 GCG* gcg
4360 )
4361{
4362 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4363 assert(conshdlrdata != NULL);
4364
4365 if( conshdlrdata->detprobdataorig == NULL )
4366 return 0;
4367
4368 return (int) conshdlrdata->detprobdataorig->getNPartialdecs();
4369}
4370
4371
4373 GCG* gcg
4374 )
4375{
4376 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4377 assert(conshdlrdata != NULL);
4378
4379 if( conshdlrdata->detprobdatapres == NULL )
4380 return 0;
4381
4382 return (int) conshdlrdata->detprobdatapres->getNPartialdecs();
4383}
4384
4385
4387 PARTIALDECOMP_C* partialdecomp
4388 )
4389{
4390 /* get partialdec and returns the number of its stairlinking vars */
4391 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4392 assert(partialdec != NULL);
4393 return partialdec->getNTotalStairlinkingvars();
4394}
4395
4396
4397std::vector<PARTIALDECOMP*>* GCGconshdlrDecompGetPartialdecs(
4398 GCG* gcg /**< GCG data structure */
4399 )
4400{
4401 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4402 assert(conshdlrdata != NULL);
4403
4404 return conshdlrdata->partialdecs;
4405}
4406
4407
4409 GCG* gcg,
4410 int partialdecid,
4411 PARTIALDECOMP_C** partialdecomp
4412 )
4413{
4414 PARTIALDECOMP* s;
4415
4416 s = GCGconshdlrDecompGetPartialdecFromID(gcg, partialdecid);
4417 *partialdecomp = reinterpret_cast<PARTIALDECOMP_C*>(s);;
4418
4419 return SCIP_OKAY;
4420}
4421
4422
4424 PARTIALDECOMP_C* partialdecomp
4425 )
4426{
4427 /* get partialdec and returns its score in respect to the current score type */
4428 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4429 assert(partialdec != NULL);
4430 return partialdec->getScore();
4431}
4432
4433
4435 GCG* gcg,
4436 int** idlist,
4437 int* listlength
4438 )
4439{
4440 /* get list of selected partialdecs */
4441 std::vector<PARTIALDECOMP*> selectedpartialdecs;
4442 getSelectedPartialdecs(gcg, selectedpartialdecs);
4443 /* set the length of the pointer array to the list size */
4444 *listlength = (int) selectedpartialdecs.size();
4445
4446 /* build a pointer list of ids from the partialdec list */
4447 for(int i = 0; i < (int) selectedpartialdecs.size(); i++)
4448 {
4449 (*idlist)[i] = selectedpartialdecs[i]->getID();
4450 }
4451
4452 return SCIP_OKAY;
4453}
4454
4455
4457 GCG* gcg
4458 )
4459{
4460 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4461 assert(conshdlrdata != NULL);
4462
4463 ++conshdlrdata->ncallscreatedecomp;
4464
4465 return conshdlrdata->ncallscreatedecomp;
4466}
4467
4468
4470 PARTIALDECOMP_C* partialdecomp
4471 )
4472{
4473 /* get partialdec and returns whether it is presolved */
4474 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4475 assert(partialdec != NULL);
4476 return !partialdec->isAssignedToOrigProb();
4477}
4478
4479
4481 PARTIALDECOMP_C* partialdecomp
4482 )
4483{
4484 /* get partialdec and returns whether it is currently selected */
4485 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4486 assert(partialdec != NULL);
4487 return partialdec->isSelected();
4488}
4489
4490
4492 GCG* gcg
4493 )
4494{
4495 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4496 assert(conshdlrdata != NULL);
4497
4498 if(conshdlrdata->detprobdataorig == NULL)
4499 return FALSE;
4500
4501 return TRUE;
4502}
4503
4504
4506 GCG* gcg
4507 )
4508{
4509 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4510 assert(conshdlrdata != NULL);
4511
4512 if( conshdlrdata->detprobdataorig == NULL )
4513 return FALSE;
4514
4515 return conshdlrdata->detprobdataorig->getNPartialdecs() > 0;
4516}
4517
4518
4520 GCG* gcg
4521 )
4522{
4523 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4524 assert(conshdlrdata != NULL);
4525
4526 if(conshdlrdata->detprobdatapres == NULL)
4527 return FALSE;
4528
4529 return TRUE;
4530}
4531
4532
4534 GCG* gcg,
4535 FILE* file
4536 )
4537{
4538 int i;
4540 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4541 assert(conshdlrdata != NULL);
4542
4543 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "Detector statistics: time #decompositions #complete decompositions\n");
4544 for( i = 0; i < conshdlrdata->ndetectors; ++i )
4545 {
4547 " %-17.16s: %8.2f %10d %10d\n",
4548 conshdlrdata->detectors[i]->name, conshdlrdata->detectors[i]->dectime,
4549 conshdlrdata->detectors[i]->ndecomps, conshdlrdata->detectors[i]->ncompletedecomps );
4550 }
4551 return SCIP_OKAY;
4552}
4553
4554
4556 GCG* gcg,
4557 FILE* file
4558 )
4559{
4561 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "Score statistics:\n");
4562 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, " Total Time : %8.2f\n",
4564 return SCIP_OKAY;
4565}
4566
4567
4569 GCG* gcg,
4570 PARTIALDECOMP* partialdec
4571 )
4572{
4573 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4574
4575 // do not register a partialdecomp multiple times
4576 if( conshdlrdata->partialdecsbyid->find(partialdec->getID()) == conshdlrdata->partialdecsbyid->end())
4577 {
4578 conshdlrdata->partialdecs->push_back(partialdec);
4579 conshdlrdata->partialdecsbyid->emplace(partialdec->getID(), partialdec);
4580 }
4581}
4582
4583
4585 PARTIALDECOMP_C* partialdecomp,
4586 SCIP_Bool select
4587 )
4588{
4589 PARTIALDECOMP* partialdec = reinterpret_cast<gcg::PARTIALDECOMP*>(partialdecomp);
4590 if( partialdec )
4591 partialdec->setSelected(select);
4592 else
4593 return SCIP_INVALIDDATA;
4594 return SCIP_OKAY;
4595}
4596
4597
4599 GCG* gcg,
4600 SCIP_PARAMSETTING paramsetting,
4601 SCIP_Bool quiet
4602)
4603{
4604 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4605 assert(conshdlrdata != NULL);
4606
4607 switch( paramsetting )
4608 {
4610 SCIP_CALL( setDetectionAggressive(gcg, conshdlrdata, quiet) );
4611 break;
4613 SCIP_CALL( setDetectionOff(gcg, conshdlrdata, quiet) );
4614 break;
4616 SCIP_CALL( setDetectionFast(gcg, conshdlrdata, quiet) );
4617 break;
4619 SCIP_CALL( setDetectionDefault(gcg, conshdlrdata, quiet) );
4620 break;
4621 default:
4622 SCIPerrorMessage("The given paramsetting is invalid!\n");
4623 break;
4624 }
4625
4626 return SCIP_OKAY;
4627}
4628
4630 GCG* gcg,
4631 int n,
4632 SCIP_Bool completeGreedily,
4633 SCIP_Bool translateSymmetry
4634)
4635{
4636 std::vector<std::pair<PARTIALDECOMP*, SCIP_Real> > candidates;
4637 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4638 assert(conshdlrdata != NULL);
4639
4640 if( conshdlrdata->detprobdataorig == NULL )
4641 {
4644 return SCIP_OKAY;
4645 }
4646
4647 if( conshdlrdata->detprobdatapres == NULL )
4649
4650 if( conshdlrdata->detprobdataorig->getNOpenPartialdecs() == 0 && conshdlrdata->detprobdataorig->getNFinishedPartialdecs() == 0 )
4651 {
4652 return SCIP_OKAY;
4653 }
4654
4656 if ( !candidates.empty() )
4657 {
4658 n = MIN(n, (int)candidates.size());
4659
4660 std::vector<PARTIALDECOMP *> origpartialdecs(n);
4661 for( int i = 0; i < n; ++i )
4662 origpartialdecs[i] = candidates[i].first;
4663
4664 std::vector<PARTIALDECOMP *> partialdecstranslated = conshdlrdata->detprobdatapres->translatePartialdecs(
4665 conshdlrdata->detprobdataorig, origpartialdecs, translateSymmetry);
4666
4667 if( !partialdecstranslated.empty())
4668 {
4669 PARTIALDECOMP *newpartialdec = partialdecstranslated[0];
4670 if( completeGreedily && !newpartialdec->isComplete() )
4671 newpartialdec->completeGreedily();
4672 SCIP_CALL(addPartialdec(gcg, newpartialdec));
4673 }
4674 }
4675
4676 return SCIP_OKAY;
4677}
4678
4679
4681 GCG* gcg
4682 )
4683{
4685 std::vector<PARTIALDECOMP*>::iterator partialdeciter;
4686 std::vector<PARTIALDECOMP*>::iterator partialdeciterend;
4687 int nmaxpresolrounds;
4688
4689 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4690 assert(conshdlrdata != NULL);
4691
4692 if( conshdlrdata->detprobdataorig == NULL )
4693 {
4696 return SCIP_OKAY;
4697 }
4698
4699 if( conshdlrdata->detprobdatapres == NULL )
4701
4702 if( conshdlrdata->detprobdataorig->getNOpenPartialdecs() == 0 && conshdlrdata->detprobdataorig->getNFinishedPartialdecs() == 0 )
4703 {
4704 return SCIP_OKAY;
4705 }
4706
4707 SCIPgetIntParam(scip, "presolving/maxrounds", &nmaxpresolrounds);
4708 std::vector<PARTIALDECOMP*> partialdecstranslated = conshdlrdata->detprobdatapres->translatePartialdecs(conshdlrdata->detprobdataorig, nmaxpresolrounds == 0);
4709
4710 partialdeciter = partialdecstranslated.begin();
4711 partialdeciterend = partialdecstranslated.end();
4712
4713 for(; partialdeciter != partialdeciterend; ++partialdeciter )
4714 {
4715 SCIP_CALL(addPartialdec(gcg, *partialdeciter) );
4716 }
4717
4718 return SCIP_OKAY;
4719}
4720
4721
4723 GCG* gcg,
4724 SCIP_Bool original
4725 )
4726{
4727 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4728 assert(conshdlrdata != NULL);
4729
4730 return original == TRUE ? conshdlrdata->hasrunoriginal : conshdlrdata->hasrun;
4731}
4732
4733
4735 GCG* gcg
4736 )
4737{
4738 long int startcount;
4739 SCIP_CONS** conss;
4741 SCIP_CONSHDLRDATA* conshdlrdata = getConshdlrdata(gcg);
4742 assert(conshdlrdata != NULL);
4743
4744 startcount = 1;
4745
4746 if( conshdlrdata->consnamesalreadyrepaired )
4747 return SCIP_OKAY;
4748
4749 unordered_map<std::string, bool> consnamemap;
4750
4751 SCIPdebugMessage("start repair conss \n ");
4752
4753 conss = SCIPgetConss(scip);
4754
4755 for( int i = 0; i < (int) SCIPgetNConss(scip); ++i )
4756 {
4757 SCIP_CONS* cons = conss[i];
4758
4759 SCIPdebugMessage( "cons name: %s\n ", SCIPconsGetName(cons));
4760
4761 if( SCIPconsGetName(cons) == NULL || strcmp(SCIPconsGetName(cons), "") == 0 || consnamemap[SCIPconsGetName(cons)] )
4762 {
4764 {
4765 char newconsname[SCIP_MAXSTRLEN];
4766 startcount = findGenericConsname(scip, startcount, newconsname, SCIP_MAXSTRLEN) + 1;
4767 SCIPdebugMessage( "Change consname to %s\n", newconsname );
4768 SCIPchgConsName(scip, cons, newconsname );
4769 consnamemap[newconsname] = true;
4770 }
4771 else
4772 {
4773 if ( SCIPconsGetName(cons) == NULL )
4774 SCIPwarningMessage(scip, "Name of constraint is NULL \n");
4775 else if ( strcmp(SCIPconsGetName(cons), "") == 0 )
4776 SCIPwarningMessage(scip, "Name of constraint is not set \n");
4777 else
4778 SCIPwarningMessage(scip, "Constraint name duplicate: %s \n", SCIPconsGetName(cons) );
4779 }
4780 }
4781 else
4782 {
4783 consnamemap[SCIPconsGetName(cons)] = true;
4784 }
4785
4786 SCIPdebugMessage( " number of elements: %d \n " , (int) consnamemap.size() );
4787 }
4788
4789 conshdlrdata->consnamesalreadyrepaired = TRUE;
4790
4791 return SCIP_OKAY;
4792}
4793
4794
4796 GCG* gcg
4797 )
4798{
4799 SCIP_CONSHDLR* conshdlr = NULL;
4800 SCIP_CONSHDLRDATA* conshdlrdata = NULL;
4801 SCIP* origprob = GCGgetOrigprob(gcg);
4802 assert(origprob != NULL);
4803
4804 /* create decomp constraint handler data */
4805 SCIP_CALL( SCIPallocMemory(origprob, &conshdlrdata) );
4806 assert(conshdlrdata != NULL);
4807
4808 /* initialize conshdlrdata */
4809 conshdlrdata->gcg = gcg;
4810 conshdlrdata->partialdecs = new std::vector<PARTIALDECOMP*>();
4811 conshdlrdata->partialdecsbyid = new std::unordered_map<int, PARTIALDECOMP*>();
4812 conshdlrdata->partialdeccounter = 0;
4813 conshdlrdata->decomps = NULL;
4814 conshdlrdata->ndecomps = 0;
4815 conshdlrdata->detectors = NULL;
4816 conshdlrdata->priorities = NULL;
4817 conshdlrdata->ndetectors = 0;
4818 conshdlrdata->propagatingdetectors = NULL;
4819 conshdlrdata->npropagatingdetectors = 0;
4820 conshdlrdata->finishingdetectors = NULL;
4821 conshdlrdata->nfinishingdetectors = 0;
4822 conshdlrdata->postprocessingdetectors = NULL;
4823 conshdlrdata->npostprocessingdetectors = 0;
4824
4825 SCIP_CALL( SCIPcreateClock(origprob, &conshdlrdata->detectorclock) );
4826 SCIP_CALL( SCIPcreateClock(origprob, &conshdlrdata->completedetectionclock) );
4827
4828 conshdlrdata->hasrun = FALSE;
4829 conshdlrdata->hasrunoriginal = FALSE;
4830 conshdlrdata->ncallscreatedecomp = 0;
4831 conshdlrdata->detprobdatapres = NULL;
4832 conshdlrdata->detprobdataorig = NULL;
4833 conshdlrdata->partialdectowrite = NULL;
4834 conshdlrdata->consnamesalreadyrepaired = FALSE;
4835 conshdlrdata->userblocknrcandidates = new std::vector<int>();
4836 conshdlrdata->freeorig = TRUE;
4837
4838 /* classifiers */
4839 conshdlrdata->consclassifiers = NULL;
4840 conshdlrdata->nconsclassifiers = 0;
4841 conshdlrdata->consclassifierpriorities = NULL;
4842 conshdlrdata->varclassifiers = NULL;
4843 conshdlrdata->nvarclassifiers = 0;
4844 conshdlrdata->varclassifierpriorities = NULL;
4845
4846 /* score data */
4847 conshdlrdata->scores = NULL;
4848 conshdlrdata->currscore = NULL;
4849 conshdlrdata->nscores = 0;
4850 conshdlrdata->scoreclock = NULL;
4851 SCIPcreateClock(origprob, &conshdlrdata->scoreclock);
4852
4853 /* include constraint handler */
4856 consEnfolpDecomp, consEnfopsDecomp, consCheckDecomp, consLockDecomp,
4857 conshdlrdata) );
4858 assert(conshdlr != FALSE);
4859
4860 SCIP_CALL( SCIPsetConshdlrEnforelax(origprob, conshdlr, consEnforeDecomp) );
4861 SCIP_CALL( SCIPsetConshdlrFree(origprob, conshdlr, consFreeDecomp) );
4862 SCIP_CALL( SCIPsetConshdlrInit(origprob, conshdlr, consInitDecomp) );
4863 SCIP_CALL( SCIPsetConshdlrExit(origprob, conshdlr, consExitDecomp) );
4864
4865 /* add menu parameters for detection */
4866 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/enabled", "Enables detection", &conshdlrdata->enabled, FALSE, DEFAULT_ENABLED, NULL, NULL) );
4867
4868 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/postprocess", "Enables postprocessing of complete decompositions",
4869 &conshdlrdata->postprocess, FALSE, DEFAULT_POSTPROCESS, NULL, NULL) );
4870
4871 SCIP_CALL( SCIPaddIntParam(origprob, "detection/maxrounds",
4872 "Maximum number of detection loop rounds", &conshdlrdata->maxndetectionrounds, FALSE,
4873 DEFAULT_MAXDETECTIONROUNDS, 0, INT_MAX, NULL, NULL) );
4874
4875 SCIP_CALL( SCIPaddIntParam(origprob, "detection/maxtime",
4876 "Maximum detection time in seconds", &conshdlrdata->maxdetectiontime, FALSE,
4877 DEFAULT_MAXDETECTIONTIME, 0, INT_MAX, NULL, NULL) );
4878
4879 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/origprob/enabled", "Enables detection for the original problem",
4881
4882 SCIP_CALL( SCIPaddIntParam(origprob, "detection/origprob/weightinggpresolvedoriginaldecomps",
4883 "Weighting method when comparing decompositions for presolved and orig problem", &conshdlrdata->weightinggpresolvedoriginaldecomps, TRUE,
4884 NO_MODIF, 0, 3, NULL, NULL) );
4885
4886 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/benders/onlycontsubpr", "If enabled only decomposition with only continiuous variables in the subproblems are searched",
4888
4889 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/benders/onlybinmaster", "If enabled only decomposition with only binary variables in the master are searched",
4891
4892 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/benders/enabled", "Enables benders detection",
4893 &conshdlrdata->detectbenders, FALSE, DEFAULT_DETECTBENDERS, NULL, NULL) );
4894
4895 /* classification */
4896 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/classification/enabled", "Enables classification", &conshdlrdata->classify, FALSE, DEFAULT_CLASSIFY, NULL, NULL) );
4897
4898 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/classification/allowduplicates", "If enabled partition duplicates are allowed (for statistical reasons)",
4900
4901 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/origprob/classificationenabled", "Enables classification for the original problem",
4903
4904 SCIP_CALL( SCIPaddIntParam(origprob, "detection/classification/maxnclassesperpartition",
4905 "Maximum number of classes per partition", &conshdlrdata->maxnclassesperpartition, FALSE,
4906 DEFAULT_MAXNCLASSES, 0, INT_MAX, NULL, NULL) );
4907
4908 SCIP_CALL( SCIPaddIntParam(origprob, "detection/classification/maxnclassesperpartitionforlargeprobs",
4909 "Maximum number of classes per partition for large problems (nconss + nvars >= 50000)", &conshdlrdata->maxnclassesperpartitionforlargeprobs, FALSE,
4910 DEFAULT_MAXNCLASSESLARGEPROBS, 0, INT_MAX, NULL, NULL) );
4911
4912 /* block numbers */
4913 SCIP_CALL( SCIPaddIntParam(origprob, "detection/blocknrcandidates/maxnclasses",
4914 "Maximum number of classes a partition can use for voting nblockcandidates", &conshdlrdata->maxnclassesfornblockcandidates, FALSE,
4916
4917 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/blocknrcandidates/medianvarspercons",
4918 "Enables the use of medianvarspercons calculation for block number candidates calculation ",
4919 &conshdlrdata->blocknumbercandsmedianvarspercons,
4921
4922 /* scores */
4923 SCIP_CALL( SCIPaddStringParam(origprob, "detection/scores/selected",
4924 "Sets the score calculation for comparing (partial) decompositions (use score shortname)",
4925 &conshdlrdata->currscore,
4926 FALSE, DEFAULT_SCORE, paramChgdScore, NULL) );
4927
4928 return SCIP_OKAY;
4929}
static SCIP_RETCODE partition(SCIP *scip, SCIP_VAR **J, int *Jsize, SCIP_Longint *priority, SCIP_VAR **F, int Fsize, SCIP_VAR **origvar, SCIP_Real *median)
SCIP_VAR * a
SCIP_VAR ** b
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
GCG_EXPORT ConsPartition * reduceClasses(int maxNumberOfClasses)
GCG_EXPORT void addPartialdecToAncestor(PARTIALDECOMP *partialdec)
adds a partialdec to ancestor partialdecs
GCG_EXPORT bool addPartialdecToOpen(PARTIALDECOMP *partialdec)
adds a partialdec to current partialdecs (data structure for partialdecs that are goin to processed i...
GCG_EXPORT ConsPartition * getConsPartition(int partitionIndex)
returns pointer to a constraint partition
GCG_EXPORT int getIndexForCons(SCIP_CONS *cons)
returns the constraint index related to a SCIP constraint
GCG_EXPORT int getNConss()
returns the number of variables considered in the detprobdata
GCG_EXPORT std::vector< SCIP_VAR * > getOrigVarsFixedZero()
returns pointers to all orig vars that are fixed to zero
GCG_EXPORT int getNVarsForCons(int consIndex)
returns the number of variables for a given constraint
GCG_EXPORT PARTIALDECOMP * getFinishedPartialdec(int partialdecindex)
returns a partialdec from finished partialdec data structure
GCG_EXPORT int getNNonzeros()
returns the number of nonzero entries in the coefficient matrix
GCG_EXPORT int getNVars()
return the number of variables considered in the detprobdata
SCIP_Real nblockscandidatescalctime
GCG_EXPORT void freeTemporaryData()
frees temporary data that is only needed during the detection process
GCG_EXPORT void addVarPartition(VarPartition *partition)
adds a variable partition if it is no duplicate of an existing variable partition
GCG_EXPORT void addPartialdecToFinishedUnchecked(PARTIALDECOMP *partialdec)
adds a partialdec to finished partialdecs without checking for duplicates, dev has to check this on h...
GCG_EXPORT int getNPartialdecs()
GCG_EXPORT SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
GCG_EXPORT void printBlockcandidateInformation(FILE *file)
output method for json file writer to write block candidate information
SCIP_Real postprocessingtime
GCG_EXPORT std::vector< SCIP_CONS * > getRelevantConss()
returns pointers to all constraints that are not marked as deleted or obsolete
GCG_EXPORT VarPartition * getVarPartition(int partitionIndex)
returns pointer to a variable partition with given index
GCG_EXPORT std::vector< PARTIALDECOMP * > & getFinishedPartialdecs()
gets all finished partialdecs
std::vector< std::pair< int, int > > candidatesNBlocks
GCG_EXPORT bool addPartialdecToFinished(PARTIALDECOMP *partialdec)
adds a partialdec to finished partialdecs
GCG_EXPORT int getNFinishedPartialdecs()
GCG_EXPORT int getNOpenPartialdecs()
returns size of current (open) partialdec data structure
GCG_EXPORT int getIndexForVar(SCIP_VAR *var)
returns the variable index related to a SCIP variable
GCG_EXPORT void sortFinishedForScore()
sorts partialdecs in finished partialdecs data structure according to the current scoretype
GCG_EXPORT void printPartitionInformation(FILE *file)
output method for json file writer to write partition candidate information
GCG_EXPORT std::vector< PARTIALDECOMP * > translatePartialdecs(DETPROBDATA *otherdata, std::vector< PARTIALDECOMP * > otherpartialdecs, SCIP_Bool translateSymmetry)
translates partialdecs if the index structure of the problem has changed, e.g. due to presolving
GCG_EXPORT void addCandidatesNBlocksNVotes(int candidate, int nvotes)
adds a candidate for block number and counts how often a candidate is added
GCG_EXPORT int getNVarPartitions()
returns number of different variable partitions
GCG_EXPORT int getNConsPartitions()
returns number of different constraint partitions
std::vector< ConsPartition * > conspartitioncollection
std::vector< VarPartition * > varpartitioncollection
GCG_EXPORT void addConsPartition(ConsPartition *partition)
adds a constraint partition if it is no duplicate of an existing constraint partition
SCIP_Real classificationtime
GCG_EXPORT std::vector< PARTIALDECOMP * > & getOpenPartialdecs()
determines all partialdecs from current (open) partialdec data structure
GCG_EXPORT std::vector< SCIP_VAR * > getRelevantVars()
returns pointers to all problem vars that are not fixed to 0
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
GCG_EXPORT void clearCurrentPartialdecs()
clears current partialdec data structure
GCG_EXPORT const char * getName()
class to manage partial decompositions
GCG_EXPORT std::vector< SCIP_Real > & getPctVarsToBorderVector()
Gets fraction of variables assigned to the border for detectors in detectorchain.
GCG_EXPORT int getNConss()
Gets the number of constraints.
GCG_EXPORT int getNMasterconss()
Gets size of the vector containing master conss.
GCG_EXPORT SCIP_Bool shouldCompletedByConsToMaster()
Checks whether this partialdec is a userpartialdec that should be completed.
GCG_EXPORT std::vector< GCG_DETECTOR * > & getDetectorchain()
returns detector chain as vector of detector pointers
GCG_EXPORT void fixVarToStairlinking(int var, int firstblock)
adds a variable to the stairlinking variables
GCG_EXPORT int getNEquivalenceClasses()
Gets the number of blockrepresentatives.
GCG_EXPORT std::vector< int > & getStairlinkingvars(int block)
Gets vector containing stairlinking vars,.
GCG_EXPORT void prepare()
GCG_EXPORT SCIP_Real getScore(GCG_SCORE *score)
returns the score of the partialdec
GCG_EXPORT int getAncestorID(int ancestorindex)
gets partialdec id of given ancestor id
GCG_EXPORT bool checkConsistency()
Checks whether the assignments in the partialdec are consistent.
GCG_EXPORT void setSelected(bool selected)
set the selection status of this partialdecs
GCG_EXPORT int getNStairlinkingvars(int block)
Gets size of the vector containing stairlinking vars.
GCG_EXPORT std::vector< SCIP_Real > & getPctConssToBlockVector()
Gets fraction of constraints assigned to a block for detectors in detectorchain.
GCG_EXPORT USERGIVEN getUsergiven()
Gets the USERGIVEN status of this partialdecs.
GCG_EXPORT void setNBlocks(int nblocks)
sets number of blocks, only increasing number allowed
GCG_EXPORT std::vector< SCIP_Real > & getDetectorClockTimes()
returns a vector of the clock times that each detector needed that was involved in this partialdec
GCG_EXPORT void fixConsToBlock(int cons, int block)
adds a constraint to a block
GCG_EXPORT int getNOpenvars()
Gets size of vector containing variables not assigned yet.
GCG_EXPORT int getVarProbindexForBlock(int varid, int block)
Gets the index of a variable in the vector returned by PARTIALDECOMP::getVarsForBlock.
GCG_EXPORT std::vector< int > & getMasterconss()
Gets array containing all master conss indices.
GCG_EXPORT void addPctVarsToBorder(SCIP_Real pct)
adds percentage of variables assigned to border
GCG_EXPORT int getNDetectors()
Gets the number of detectors the partialdec is propagated by.
GCG_EXPORT void completeGreedily()
assigns all open constraints and open variables
GCG_EXPORT std::vector< int > & getConssForBlock(int block)
returns array containing constraints assigned to a block
GCG_EXPORT const std::vector< int > & getBlocksForEqClass(int eqclass)
get a vector of block ids that are contained in the equivalence class eqclass
GCG_EXPORT void buildDecChainString(char *buffer)
creates a detector chain short string for this partialdec, is built from detector chain
GCG_EXPORT DETPROBDATA * getDetprobdata()
Gets the corresponding detprobdata.
GCG_EXPORT bool isComplete()
Gets whether this partialdec is complete, i.e. it has no more open constraints and variables.
GCG_EXPORT void setFinishedByFinisher(bool finished)
sets whether this partialdec was finished by a finishing detector
GCG_EXPORT void addPctVarsFromFree(SCIP_Real pct)
adds percentage of closed variables
GCG_EXPORT int getNOpenconss()
Gets size of vector containing constraints not assigned yet.
GCG_EXPORT void calcAggregationInformation(bool ignoreDetectionLimits)
computes if aggregation of sub problems is possible
GCG_EXPORT int getNVarsForBlock(int block)
Gets size of the vector containing vars assigned to a block.
GCG_EXPORT void setDetectorFinished(GCG_DETECTOR *detector)
sets detector that finished the partialdec
GCG_EXPORT void fixVarToLinking(int var)
adds a variable to the linking variables
GCG_EXPORT bool aggInfoCalculated()
Checks if the aggregation information was already calculated.
GCG_EXPORT std::vector< int > & getLinkingvars()
returns array containing all linking vars indices
GCG_EXPORT void fixVarToMaster(int var)
adds a variable to the master variables
GCG_EXPORT void addPctConssToBorder(SCIP_Real pct)
adds percentage of constraints assigned to border
GCG_EXPORT void assignOpenConssToMaster()
assigns open conss to master
GCG_EXPORT int getEqClassForBlock(int blockid)
Gets index of the representative block for a block, this might be blockid itself.
GCG_EXPORT SCIP_Bool hasSetppccardMaster()
checks if all master constraints set partitioning, set packing, set cover, or cardinality constraints
GCG_EXPORT bool isAssignedToOrigProb()
Gets whether the partialdec is from the original problem.
GCG_EXPORT int getNVars()
Gets number of vars.
GCG_EXPORT void setDetectorPropagated(GCG_DETECTOR *detector)
sets partialdec to be propagated by a detector
GCG_EXPORT void addPctConssToBlock(SCIP_Real pct)
adds percentage of constraints assigned to blocks
GCG_EXPORT std::vector< int > & getMastervars()
Gets array containing all master vars indices.
GCG_EXPORT void setUsergiven(USERGIVEN usergiven)
sets whether this partialdec is user given
GCG_EXPORT std::vector< SCIP_Real > & getPctConssToBorderVector()
Gets fraction of constraints assigned to the border for detectors in detectorchain.
GCG_EXPORT int getNLinkingvars()
Gets size of the vector containing linking vars.
GCG_EXPORT std::vector< SCIP_Real > & getPctVarsFromFreeVector()
Gets fraction of variables that are not longer open for detectors in detectorchain.
GCG_EXPORT void deleteEmptyBlocks(bool variables)
deletes empty blocks and sets nblocks accordingly
GCG_EXPORT SCIP_Real getMaxWhiteScore()
gets the maximum white area score
GCG_EXPORT bool isSelected()
GCG_EXPORT std::vector< int > & getRepVarmap(int eqclass, int eqclassblock)
Returns a vector that maps probvar indices of a block contained in an equivalence class to the probva...
GCG_EXPORT void addNNewBlocks(int nnewblocks)
adds how many new blocks were introduced
GCG_EXPORT int getNAncestors()
Gets number of ancestor partialdecs.
GCG_EXPORT std::vector< SCIP_Real > & getPctConssFromFreeVector()
Gets fraction of constraints that are not longer open for detectors in detectorchain.
GCG_EXPORT int getReprBlockForEqClass(int eqclass)
get the representative block of the given equivalence class
GCG_EXPORT void considerImplicits()
: assigns every open cons/var
GCG_EXPORT int getNTotalStairlinkingvars()
Gets total number of stairlinking vars.
GCG_EXPORT int getNMastervars()
Gets size of the vector containing master vars.
GCG_EXPORT int getNConssForBlock(int block)
Gets size of the vector containing conss assigned to a block.
GCG_EXPORT void addDecChangesFromAncestor(PARTIALDECOMP *ancestor)
adds the statistical differences to an ancestor
GCG_EXPORT void addPctConssFromFree(SCIP_Real pct)
adds percentage of closed constraints
GCG_EXPORT int getID()
returns the unique id of the partialdec
GCG_EXPORT void addClockTime(SCIP_Real clocktime)
adds detection time of one detector
GCG_EXPORT int getTranslatedpartialdecid() const
GCG_EXPORT std::vector< int > & getOpenconss()
Gets vector containing constraints not assigned yet.
GCG_EXPORT void reorderBlocksForStairlinkingVars()
reorders blocks for making a maximum number of linking vars stairlinking
GCG_EXPORT void printPartitionInformation(FILE *file)
prints partition information as described in
GCG_EXPORT std::vector< SCIP_Real > & getPctVarsToBlockVector()
returns fraction of variables assigned to a block for detectors in detectorchain
GCG_EXPORT std::vector< int >::const_iterator fixConsToMaster(std::vector< int >::const_iterator itr)
fixes a constraint to the master constraints
GCG_EXPORT bool sort()
sorts the vars and conss data structures by their indices
GCG_EXPORT bool isVarStairlinkingvar(int var)
Checks whether the var is a stairlinking var.
GCG_EXPORT std::vector< int > getNNewBlocksVector()
gets number of blocks the detectors in the detectorchain added
GCG_EXPORT std::vector< int > & getVarsForBlock(int block)
Gets array containing vars of a block.
GCG_EXPORT void addPctVarsToBlock(SCIP_Real pct)
adds percentage of variables assigned to blocks
GCG_EXPORT bool isPropagatedBy(GCG_DETECTOR *detector)
Gets whether this partialdec was propagated by specified detector.
GCG_EXPORT int getNBlocks()
Gets the number of blocks.
GCG_EXPORT void fixVarToBlock(int var, int block)
adds a variable to the linking variables
GCG_EXPORT VarPartition * reduceClasses(int maxNumberOfClasses)
void GCGconshdlrDecompDeregisterPartialdecs(GCG *gcg, SCIP_Bool original)
deregisters partialdecs in the conshdlr
std::vector< PARTIALDECOMP * > * GCGconshdlrDecompGetPartialdecs(GCG *gcg)
gets vector of all partialdecs
static SCIP_DECL_CONSENFOLP(consEnfolpDecomp)
SCIP_RETCODE GCGconshdlrDecompCreateVarmapForPartialdec(SCIP *scip, SCIP_HASHMAP **hashorig2pricingvar, PARTIALDECOMP_C *partialdecomp, int probnr1, int probnr2, SCIP *scip1, SCIP *scip2, SCIP_HASHMAP *varmap)
int GCGgetNDecomps(GCG *gcg)
SCIP_RETCODE GCGconshdlrDecompTranslateNBestOrigPartialdecs(GCG *gcg, int n, SCIP_Bool completeGreedily, SCIP_Bool translateSymmetry)
translates n best unpresolved partialdec to a complete presolved one
SCIP_Bool GCGconshdlrDecompPartialdecAggregationInformationCalculated(PARTIALDECOMP_C *partialdecomp)
returns whether aggregation information has been calculated for a partialdec
#define CONSHDLR_NEEDSCONS
Definition: cons_decomp.cpp:87
int GCGconshdlrDecompPartialdecGetReprBlockForEqClass(PARTIALDECOMP_C *partialdecomp, int eqclass)
gets the representative block of a equivalence class of partialdec
int GCGconshdlrDecompPartialdecGetNMasterVars(PARTIALDECOMP_C *partialdecomp)
gets number of master variables of partialdec
static int findGenericConsname(SCIP *scip, int startcount, char *consname, int namelength)
finds a non duplicate constraint name of the form c_{a} with minimal natural number {a}
#define DEFAULT_SCORE
static SCIP_RETCODE setDetectionDefault(GCG *gcg, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_Bool quiet)
resets the parameters to their default value
static PARTIALDEC_DETECTION_DATA * createPartialdecDetectionData(gcg::DETPROBDATA *detprobdata, PARTIALDECOMP *partialdec)
initializes a new detection data structure
void GCGconshdlrDecompAddCandidatesNBlocks(GCG *gcg, SCIP_Bool origprob, int candidate)
adds a candidate for block number and counts how often a candidate is added
#define CONSHDLR_CHECKPRIORITY
Definition: cons_decomp.cpp:84
static SCIP_DECL_CONSENFORELAX(consEnforeDecomp)
static SCIP_RETCODE setDetectionOff(GCG *gcg, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_Bool quiet)
disables detectors
#define CONSHDLR_DESC
Definition: cons_decomp.cpp:82
SCIP_Real GCGconshdlrDecompGetCompleteDetectionTime(GCG *gcg)
returns the total detection time
int GCGconshdlrDecompGetNBlockNumberCandidates(GCG *gcg)
returns the number of block candidates given by the user
void GCGconshdlrDecompFreeOrigOnExit(GCG *gcg, SCIP_Bool free)
sets freeing of detection data of original problem during exit to true
static void reduceConsclasses(GCG *gcg, gcg::DETPROBDATA *detprobdata)
adds constraint partitions with a reduced number of classes
#define FAST_LEVENSHTEIN_MAXMATRIXHALFPERIMETER
GCG_CONSCLASSIFIER * GCGfindConsClassifier(GCG *gcg, const char *name)
searches for the consclassifier with the given name and returns it or NULL if classifier is not found
const char * GCGdetectorGetName(GCG_DETECTOR *detector)
returns the name of the provided detector
GCG_VARCLASSIFIER * GCGfindVarClassifier(GCG *gcg, const char *name)
searches for the varclassifier with the given name and returns it or NULL if classifier is not found
static SCIP_RETCODE createPartialdecFromDecomp(GCG *gcg, GCG_DECOMP *decomp, PARTIALDECOMP **newpartialdec)
creates a partialdec for a given decomposition
std::string GCGconshdlrDecompPartialdecGetDetectorHistory(PARTIALDECOMP_C *partialdecomp)
static SCIP_CONSHDLRDATA * getConshdlrdata(GCG *gcg)
local function to get the conshdlr data of the current conshdlr
#define DEFAULT_POSTPROCESS
Definition: cons_decomp.cpp:95
GCG_SCORE ** GCGconshdlrDecompGetScores(GCG *gcg)
Gets an array of all scores.
SCIP_Bool GCGconshdlrDecompCheckConsistency(GCG *gcg)
check whether partialdecs are consistent
SCIP_Real GCGconshdlrDecompAdaptScore(GCG *gcg, SCIP_Real oldscore)
method to adapt score for orig decomps
#define DEFAULT_ENABLEORIGDETECTION
Definition: cons_decomp.cpp:99
int GCGconshdlrDecompGetNDetectors(GCG *gcg)
Gets the number of all detectors.
int GCGconshdlrDecompGetNVarClassifiers(GCG *gcg)
Gets the number of all variable classifiers.
const int * GCGconshdlrDecompPartialdecGetBlocksForEqClass(PARTIALDECOMP_C *partialdecomp, int eqclass)
gets the blocks of a equivalence class of partialdec
#define DEFAULT_BENDERSONLYCONTSUBPR
SCIP_RETCODE GCGconshdlrDecompClassify(GCG *gcg, SCIP_Bool transformed)
run classification of vars and cons
SCIP_RETCODE GCGwriteAllDecomps(GCG *gcg, char *directory, char *extension, SCIP_Bool original, SCIP_Bool presolved)
write out all known decompositions
int GCGconshdlrDecompDecreaseNCallsCreateDecomp(GCG *gcg)
decreases the counter for created decompositions and returns it
SCIP_RETCODE GCGconshdlrDecompTranslateOrigPartialdecs(GCG *gcg)
translates unpresolved partialdec to a complete presolved one
static void getFinishedPartialdecs(GCG *gcg, std::vector< PARTIALDECOMP * > &finishedpartialdecs)
gets vector of all finished partialdecs
void GCGconshdlrDecompCalcCandidatesNBlocks(GCG *gcg, SCIP_Bool transformed)
calculates and adds block size candidates using constraint classifications and variable classificatio...
#define DEFAULT_MAXDETECTIONROUNDS
Definition: cons_decomp.cpp:93
static SCIP_RETCODE setDetectionFast(GCG *gcg, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_Bool quiet)
sets the parameters to fast values
static SCIP_DECL_CONSFREE(consFreeDecomp)
destructor of constraint handler to free constraint handler data (called when SCIP is exiting)
SCIP_RETCODE GCGconshdlrDecompAddPreexistingDecomp(GCG *gcg, GCG_DECOMP *decomp)
adds a decomp that exists before the detection is called
int GCGconshdlrDecompPartialdecGetNEquivalenceClasses(PARTIALDECOMP_C *partialdecomp)
gets number of equivalence classes of partialdec
static SCIP_RETCODE resetDetprobdata(GCG *gcg, SCIP_Bool original)
resets/creates the detprobdata for the given problem
SCIP_RETCODE GCGconshdlrDecompArePricingprobsIdenticalForPartialdec(SCIP *scip, PARTIALDECOMP_C *partialdecomp, int probnr1, int probnr2, SCIP_Bool *identical)
static SCIP_DECL_CONSLOCK(consLockDecomp)
SCIP_Real GCGgetRemainingTime(GCG *gcg)
returns the remaining time of scip that the decomposition may use
const int * GCGconshdlrDecompPartialdecGetRepVarMap(PARTIALDECOMP_C *partialdecomp, int eqclass, int eqclassblock)
Returns a vector that maps probvar indices of a block contained in an equivalence class to the probva...
SCIP_Bool GCGconshdlrDecompPresolvedDetprobdataExists(GCG *gcg)
returns whether or not a detprobdata structure for the presolved problem exists
int GCGconshdlrDecompPartialdecGetNVarsForBlock(PARTIALDECOMP_C *partialdecomp, int block)
gets the number of variables of a block
unsigned int GCGconshdlrDecompGetNFinishedPartialdecsOrig(GCG *gcg)
Gets the number of finished partialdecs available for the original problem.
GCG_SCORE * GCGconshdlrDecompFindScoreByShortname(GCG *gcg, const char *shortname)
searches for the score with the given shortname and returns it or NULL if score is not found
SCIP_Real GCGconshdlrDecompGetScoreTotalTime(GCG *gcg)
gets total score computation time
SCIP_RETCODE GCGconshdlrDecompSetDetection(GCG *gcg, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
sets detector parameters values
SCIP_RETCODE GCGwriteSelectedDecomps(GCG *gcg, char *directory, char *extension)
writes all selected decompositions
int GCGconshdlrDecompPartialdecGetNMasterConss(PARTIALDECOMP_C *partialdecomp)
gets number of master constraints of partialdec
GCG_VARCLASSIFIER ** GCGconshdlrDecompGetVarClassifiers(GCG *gcg)
gets an array of all variable classifier
static SCIP_RETCODE setDetectionEnabled(GCG *gcg, SCIP_Bool quiet, SCIP_Bool enabled)
sets detection/enabled setting
#define DEFAULT_LEVENSHTEIN_MAXMATRIXHALFPERIMETER
static SCIP_RETCODE deletePartialdecDetectionData(SCIP *scip, PARTIALDEC_DETECTION_DATA *data)
delets the detection data structure
#define DEFAULT_MAXDETECTIONTIME
Definition: cons_decomp.cpp:94
int GCGconshdlrDecompPartialdecGetNOpenConss(PARTIALDECOMP_C *partialdecomp)
gets number of open constraints of partialdec
#define DEFAULT_MAXNCLASSESFORNBLOCKCANDIDATES
Definition: cons_decomp.cpp:98
SCIP_Bool GCGconshdlrDecompIsSelected(PARTIALDECOMP_C *partialdecomp)
SCIP_VAR * GCGconshdlrDecompPartialdecGetOrigVarForBlock(PARTIALDECOMP_C *partialdecomp, int block, int blockvarindex)
returns the original variable for a block and index
int GCGconshdlrDecompGetNextPartialdecID(GCG *gcg)
Gets the next partialdec id managed by cons_decomp.
GCG_DETECTORDATA * GCGdetectorGetData(GCG_DETECTOR *detector)
returns the data of the provided detector
void GCGconshdlrDecompRegisterPartialdec(GCG *gcg, PARTIALDECOMP *partialdec)
registers a partialdec in the conshdlr
void GCGconshdlrDecompFreeDetprobdata(GCG *gcg)
Frees Detprobdata of the original and transformed/presolved problem.
void GCGconshdlrDecompDeregisterPartialdec(GCG *gcg, PARTIALDECOMP *partialdec)
deregisters a partialdec in the conshdlr
GCG_SCORE * GCGgetCurrentScore(GCG *gcg)
Gets the currently enabled score.
static void sortPartialdecs(GCG *gcg)
sorts all registered partialdecs according to score, descending
void GCGconshdlrDecompAddUserCandidatesNBlocks(GCG *gcg, int candidate)
adds a candidate for block size given by the user
GCG_CONSCLASSIFIER ** GCGconshdlrDecompGetConsClassifiers(GCG *gcg)
gets an array of all constraint classifier
SCIP_RETCODE GCGconshdlrDecompSelectPartialdec(PARTIALDECOMP_C *partialdecomp, SCIP_Bool select)
selects/unselects a partialdecomp
static SCIP_RETCODE unselectAllPartialdecs(GCG *gcg)
SCIP_Bool GCGconshdlrDecompIsPresolved(PARTIALDECOMP_C *partialdecomp)
DETPROBDATA * GCGconshdlrDecompGetDetprobdataPresolved(GCG *gcg)
help method to access detprobdata for transformed problem
#define DEFAULT_MAXNCLASSESLARGEPROBS
Definition: cons_decomp.cpp:96
static SCIP_DECL_CONSCHECK(consCheckDecomp)
SCIP_RETCODE GCGconshdlrDecompGetFinishedPartialdecsList(GCG *gcg, int **idlist, int *listlength)
Gets a list of ids of the current partialdecs that are finished.
int GCGconshdlrDecompGetNConsClassifiers(GCG *gcg)
Gets the number of all constraint classifiers.
unsigned int GCGconshdlrDecompGetNOpenPartialdecsTransformed(GCG *gcg)
Gets the number of open partialdecs available for the transformed problem.
int GCGconshdlrDecompAddMatrixPartialdec(GCG *gcg, SCIP_Bool presolved)
creates a pure matrix partialdecomp (i.e. all cons/vars to one single block)
static std::vector< PARTIALDECOMP * > getSelectedPartialdecs(GCG *gcg, std::vector< PARTIALDECOMP * > &selectedpartialdecs)
gets all selected partialdecs
SCIP_RETCODE GCGconshdlrDecompAddBasicPartialdec(GCG *gcg, SCIP_Bool presolved, PARTIALDECOMP_C **partialdecomp)
creates and adds a basic partialdecomp (all cons/vars are assigned to master)
static SCIP_DECL_CONSEXIT(consExitDecomp)
deinitialization method of constraint handler (called before transformed problem is freed)
SCIP_Real GCGconshdlrDecompPartialdecGetScore(PARTIALDECOMP_C *partialdecomp)
unsigned int GCGconshdlrDecompGetNPartialdecsTransformed(GCG *gcg)
Gets the number of partialdecs available for the transformed problem.
#define DEFAULT_MAXNCLASSES
Definition: cons_decomp.cpp:97
static SCIP_RETCODE addPartialdec(GCG *gcg, PARTIALDECOMP *partialdec)
local method to handle store a partialdec in the correct detprobdata
SCIP_RETCODE GCGincludeVarClassifier(GCG *gcg, const char *name, const char *description, int priority, SCIP_Bool enabled, GCG_CLASSIFIERDATA *classifierdata, GCG_DECL_FREEVARCLASSIFIER((*freeClassifier)),)
SCIP_Bool GCGdetectionTookPlace(GCG *gcg, SCIP_Bool original)
SCIP_Bool GCGconshdlrDecompOrigDetprobdataExists(GCG *gcg)
returns whether or not a detprobdata structure for the original problem exists
static SCIP_Retcode detect(GCG *gcg, gcg::DETPROBDATA *detprobdata)
constructs partialdecs using the registered detectors
DETPROBDATA * GCGconshdlrDecompGetDetprobdataOrig(GCG *gcg)
help method to access detprobdata for unpresolved problem
SCIP_RETCODE GCGconshdlrDecompGetPartialdecsList(GCG *gcg, int **idlist, int *listlength)
Gets a list of ids of the current partialdecs.
#define DEFAULT_BENDERSONLYBINMASTER
GCG_DETECTOR * GCGfindDetector(GCG *gcg, const char *name)
searches for the detector with the given name and returns it or NULL if detector is not found
SCIP_RETCODE GCGincludeConshdlrDecomp(GCG *gcg)
creates the constraint handler for decomp and includes it in SCIP
int GCGconshdlrDecompPartialdecGetNBlocks(PARTIALDECOMP_C *partialdecomp)
gets block number of partialdec
static SCIP_RETCODE setDetectionAggressive(GCG *gcg, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_Bool quiet)
sets the parameters to aggressive values
static SCIP_DECL_PARAMCHGD(paramChgdScore)
SCIP_RETCODE GCGdetectStructure(GCG *gcg, SCIP_RESULT *result)
interface method to detect the structure including presolving
SCIP_RETCODE GCGconshdlrDecompPrintDetectorStatistics(GCG *gcg, FILE *file)
display statistics about detectors
SCIP_RETCODE GCGconshdlrDecompChooseCandidatesFromSelected(GCG *gcg, std::vector< std::pair< gcg::PARTIALDECOMP *, SCIP_Real > > &candidates, SCIP_Bool original, SCIP_Bool printwarnings)
#define DEFAULT_ENABLEORIGCLASSIFICATION
int GCGconshdlrDecompGetNFormerDetectionConssForID(GCG *gcg, int id)
gets number of active constraints during the detection of the decomp with given id
#define AGGRESSIVE_LEVENSHTEIN_MAXMATRIXHALFPERIMETER
char * GCGgetCurrentScoreShortname(GCG *gcg)
Gets the shortname of the currently enabled score.
char GCGdetectorGetChar(GCG_DETECTOR *detector)
Gets the character of the detector.
int GCGconshdlrDecompPartialdecGetNBlocksForEqClass(PARTIALDECOMP_C *partialdecomp, int eqclass)
gets the number of blocks of a equivalence class of partialdec
static SCIP_DECL_CONSINIT(consInitDecomp)
initialization method of constraint handler (called after problem was transformed)
GCG_DECOMP ** GCGconshdlrDecompGetDecomps(GCG *gcg)
returns an array containing all decompositions
#define CONSHDLR_EAGERFREQ
Definition: cons_decomp.cpp:85
#define DEFAULT_DETECTBENDERS
unsigned int GCGconshdlrDecompGetNPartialdecsOrig(GCG *gcg)
Gets the number of partialdecs available for the original problem.
SCIP_RETCODE SCIPconshdlrDecompRepairConsNames(GCG *gcg)
int GCGconshdlrDecompGetNScores(GCG *gcg)
Gets the number of all scores.
SCIP_RETCODE GCGconshdlrDecompIncludeScore(GCG *gcg, const char *name, const char *shortname, const char *description, GCG_SCOREDATA *scoredata, GCG_DECL_SCOREFREE((*scorefree)),)
weightinggpresolvedoriginaldecomps
@ FRACTION_OF_NROWS
@ NO_MODIF
@ FRACTION_OF_NNONZEROS
@ FAVOUR_PRESOLVED
int GCGconshdlrDecompPartialdecGetNOpenVars(PARTIALDECOMP_C *partialdecomp)
gets number of open variables of partialdec
PARTIALDECOMP * GCGgetPartialdecToWrite(GCG *gcg, SCIP_Bool transformed)
void GCGprintListOfDetectors(GCG *gcg)
writes out a list of all detectors
int GCGconshdlrDecompGetNDecomps(GCG *gcg)
gets the number of decompositions (= amount of finished partialdecs)
#define CONSHDLR_ENFOPRIORITY
Definition: cons_decomp.cpp:83
unsigned int GCGconshdlrDecompGetNFinishedPartialdecsTransformed(GCG *gcg)
Gets the number of finished partialdecs available for the transformed problem.
int GCGconshdlrDecompIncreaseNCallsCreateDecomp(GCG *gcg)
counts up the counter for created decompositions and returns it
SCIP_CLOCK * GCGconshdlrDecompGetScoreClock(GCG *gcg)
gets the clock tracking the score computation time
int GCGconshdlrDecompPartialdecGetNLinkingVars(PARTIALDECOMP_C *partialdecomp)
gets number of linking variables of partialdec
static SCIP_DECL_CONSENFOPS(consEnfopsDecomp)
static SCIP_RETCODE partialdecVecToIdArray(std::vector< PARTIALDECOMP * > &partialdecs, int **idlist, int *listlength)
translates a vector of PARTIALDECOMP pointers into an array of their ids
GCG_DECOMP * GCGgetBestDecomp(GCG *gcg, SCIP_Bool printwarnings)
Gets the best known decomposition.
static SCIP_RETCODE createDecompFromPartialdec(GCG *gcg, PARTIALDECOMP *partialdec, GCG_DECOMP **newdecomp)
creates a decomposition GCG_DECOMP structure for a given partialdec
#define DEFAULT_ENABLED
Definition: cons_decomp.cpp:89
SCIP_Bool GCGconshdlrDecompOrigPartialdecExists(GCG *gcg)
returns whether or not an original decompositions exists in the data structures
#define DEFAULT_ALLOWPARTITIONDUPLICATES
unsigned int GCGconshdlrDecompGetNOpenPartialdecsOrig(GCG *gcg)
Gets the number of open partialdecs available for the original problem.
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)),)
#define CONSHDLR_NAME
Definition: cons_decomp.cpp:81
SCIP_RETCODE GCGconshdlrDecompAddPreexisitingPartialDec(GCG *gcg, PARTIALDECOMP *partialdec)
adds a preexisting partial dec to be considered at the beginning of the detection
GCG_DETECTOR ** GCGconshdlrDecompGetDetectors(GCG *gcg)
Gets an array of all detectors.
#define DEFAULT_BLOCKNUMBERCANDSMEDIANVARSPERCONS
Definition: cons_decomp.cpp:91
unsigned int GCGconshdlrDecompGetNPartialdecs(GCG *gcg)
Gets the number of all partialdecs.
GCG_SCORE * GCGconshdlrDecompFindScore(GCG *gcg, const char *name)
searches for the score with the given name and returns it or NULL if score is not found
int GCGconshdlrDecompPartialdecGetNStairlinkingVars(PARTIALDECOMP_C *partialdecomp)
gets number of stairlinking variables of partialdec
SCIP_RETCODE GCGconshdlrDecompPrintScoreStatistics(GCG *gcg, FILE *file)
display statistics about scores
#define DEFAULT_CLASSIFY
void GCGconshdlrDecompPartialdecCalcAggregationInformation(PARTIALDECOMP_C *partialdecomp, SCIP_Bool ignoreDetectionLimits)
calculates aggregation information for a partialdec
static void reduceVarclasses(GCG *gcg, gcg::DETPROBDATA *detprobdata)
adds variable partitions with a reduced number of classes
static int gcd(int a, int b)
method to calculate the greatest common divisor
SCIP_RETCODE GCGconshdlrDecompGetSelectedPartialdecs(GCG *gcg, int **idlist, int *listlength)
Gets a list of ids of all currently selected partialdecs.
SCIP_RETCODE GCGincludeConsClassifier(GCG *gcg, const char *name, const char *description, int priority, SCIP_Bool enabled, GCG_CLASSIFIERDATA *classifierdata, GCG_DECL_FREECONSCLASSIFIER((*freeClassifier)),)
int GCGconshdlrDecompGetBlockNumberCandidate(GCG *gcg, int index)
returns block number user candidate with given index
PARTIALDECOMP * GCGconshdlrDecompGetPartialdecFromID(GCG *gcg, int partialdecid)
local method to find a partialdec for a given id or NULL if no partialdec with such id is found
constraint handler for structure detection
struct PARTIALDECOMP_C PARTIALDECOMP_C
Definition: cons_decomp.h:59
C++ interface of cons_decomp.
GCG_DECL_PROPAGATEPARTIALDEC(detectorPropagatePartialdecIsomorph)
GCG_DECL_FREEDETECTOR(freeNeighborhoodmaster)
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
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
void GCGdecompSetDetector(GCG_DECOMP *decomp, GCG_DETECTOR *detector)
Definition: decomp.c:1605
SCIP_VAR *** GCGdecompGetStairlinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1173
SCIP_RETCODE GCGdecompCheckConsistency(GCG *gcg, GCG_DECOMP *decdecomp)
Definition: decomp.c:2297
void GCGdecompSetVarindex(GCG_DECOMP *decomp, SCIP_HASHMAP *varindex)
Definition: decomp.c:1253
SCIP_HASHMAP * GCGdecompGetConstoblock(GCG_DECOMP *decomp)
Definition: decomp.c:1243
SCIP_Real * GCGdecompGetDetectorPctConssToBorder(GCG_DECOMP *decomp)
Definition: decomp.c:1816
int GCGdecompGetNLinkingconss(GCG_DECOMP *decomp)
Definition: decomp.c:995
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 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
int * GCGdecompGetNNewBlocks(GCG_DECOMP *decomp)
Definition: decomp.c:1997
SCIP_CONS ** GCGdecompGetLinkingconss(GCG_DECOMP *decomp)
Definition: decomp.c:985
void GCGdecompSetNNewBlocks(GCG *gcg, GCG_DECOMP *decomp, int *nNewBlocks)
Definition: decomp.c:1970
SCIP_RETCODE GCGdecompSetLinkingvars(GCG *gcg, GCG_DECOMP *decomp, SCIP_VAR **linkingvars, int nlinkingvars, int nfixedlinkingvars, int nmastervars)
Definition: decomp.c:1007
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
SCIP_HASHMAP * GCGdecompGetVartoblock(GCG_DECOMP *decomp)
Definition: decomp.c:1221
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
SCIP_RETCODE GCGdecompSetSubscipconss(GCG *gcg, GCG_DECOMP *decomp, SCIP_CONS ***subscipconss, int *nsubscipconss)
Definition: decomp.c:857
SCIP_RETCODE GCGdecompSetLinkingconss(GCG *gcg, GCG_DECOMP *decomp, SCIP_CONS **linkingconss, int nlinkingconss)
Definition: decomp.c:942
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
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
int GCGdecompGetNLinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1066
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
SCIP_Real * GCGdecompGetDetectorPctConssFromOpen(GCG_DECOMP *decomp)
Definition: decomp.c:1962
int * GCGdecompGetNStairlinkingvars(GCG_DECOMP *decomp)
Definition: decomp.c:1182
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
void GCGdecompSetConstoblock(GCG_DECOMP *decomp, SCIP_HASHMAP *constoblock)
Definition: decomp.c:1231
GCG_EXPORT SCIP_Real * GCGdecompGetDetectorPctVarsToBorder(GCG_DECOMP *decomp)
Definition: decomp.c:1780
private methods for working with decomp structures
#define SCIP_MAXSTRLEN
#define SCIP_Bool
#define SCIP_CALL_QUIET(x)
#define MIN(x, y)
#define SCIP_ALLOC(x)
#define SCIP_Real
#define SCIP_CALL_ABORT(x)
#define SCIP_CALL(x)
#define TRUE
#define FALSE
SCIP_VAR * GCGpricingVarGetOriginalVar(SCIP_VAR *var)
Definition: gcgvar.c:590
SCIP_Bool GCGisConsGCGCons(SCIP_CONS *cons)
Definition: misc.c:836
SCIP_RETCODE GCGprintPartitionInformation(GCG *gcg, FILE *file)
SCIP_RETCODE GCGprintBlockcandidateInformation(GCG *gcg, FILE *file)
SCIP_RETCODE GCGprintCompleteDetectionTime(GCG *gcg, FILE *file)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
SCIP_RETCODE GCGprintDecompInformation(GCG *gcg, FILE *file)
GCG_EXPORT GCG_DECMODE GCGgetDecompositionMode(GCG *gcg)
Definition: relax_gcg.c:5294
SCIP_STAGE SCIPgetStage(SCIP *scip)
SCIP_RETCODE SCIPwriteOrigProblem(SCIP *scip, const char *filename, const char *extension, SCIP_Bool genericnames)
int SCIPgetNOrigConss(SCIP *scip)
SCIP_CONS ** SCIPgetConss(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
int SCIPgetNOrigVars(SCIP *scip)
SCIP_RETCODE SCIPwriteTransProblem(SCIP *scip, const char *filename, const char *extension, SCIP_Bool genericnames)
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 SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
SCIP_VERBLEVEL SCIPgetVerbLevel(SCIP *scip)
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
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 SCIPaddStringParam(SCIP *scip, const char *name, const char *desc, char **valueptr, SCIP_Bool isadvanced, const char *defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
SCIP_RETCODE SCIPresetParam(SCIP *scip, const char *name)
SCIP_RETCODE SCIPsetStringParam(SCIP *scip, const char *name, const char *value)
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPgetIntParam(SCIP *scip, const char *name, int *value)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
SCIP_RETCODE SCIPsetConshdlrInit(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINIT((*consinit)))
SCIP_RETCODE SCIPincludeConshdlrBasic(SCIP *scip, SCIP_CONSHDLR **conshdlrptr, const char *name, const char *desc, int enfopriority, int chckpriority, int eagerfreq, SCIP_Bool needscons, SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_CONSHDLRDATA *conshdlrdata)
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
SCIP_RETCODE SCIPsetConshdlrEnforelax(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENFORELAX((*consenforelax)))
SCIP_RETCODE SCIPsetConshdlrExit(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXIT((*consexit)))
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
SCIP_RETCODE SCIPchgConsName(SCIP *scip, SCIP_CONS *cons, const char *name)
SCIP_Bool SCIPconsIsDeleted(SCIP_CONS *cons)
const char * SCIPconsGetName(SCIP_CONS *cons)
SCIP_RETCODE SCIPgetTransformedCons(SCIP *scip, SCIP_CONS *cons, SCIP_CONS **transcons)
SCIP_Bool SCIPconsIsObsolete(SCIP_CONS *cons)
#define SCIPfreeMemoryArrayNull(scip, ptr)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
#define SCIPreallocMemoryArray(scip, ptr, newnum)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeMemoryArray(scip, ptr)
#define SCIPfreeMemory(scip, ptr)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPfreeBufferArrayNull(scip, ptr)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
SCIP_RETCODE SCIPcreateClock(SCIP *scip, SCIP_CLOCK **clck)
SCIP_RETCODE SCIPresetClock(SCIP *scip, SCIP_CLOCK *clck)
SCIP_RETCODE SCIPstopClock(SCIP *scip, SCIP_CLOCK *clck)
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
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 SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_VAR * SCIPvarGetProbvar(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
int SCIPsnprintf(char *t, int len, const char *s,...)
#define NULL
#define BMSduplicateMemoryArray(ptr, source, num)
#define BMSfreeMemoryArray(ptr)
void SCIPmessageFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr,...)
void GCGgetVisualizationFilename(GCG *gcg, PARTIALDECOMP *partialdec, const char *extension, char *filename)
miscellaneous methods for visualizations
struct gcg::subset subset
@ COMPLETED_CONSTOMASTER
char * SCIPparamGetString(SCIP_PARAM *param)
#define SCIPerrorMessage
#define SCIPdebugMessage
GCG relaxator.
various SCIP helper methods
GCG_CLASSIFIERDATA * clsdata
SCIP_Bool presolved
Definition: struct_decomp.h:54
SCIP_Bool overruleemphasis
const char * description
SCIP_Bool usefulRecall
int freqCallRoundOriginal
int maxCallRoundOriginal
SCIP_Bool enabledPostprocessing
SCIP_Bool enabledFinishing
int minCallRoundOriginal
SCIP_Bool skip
const char * name
SCIP_Real dectime
SCIP_Bool enabled
GCG_DETECTORDATA * decdata
const char * name
Definition: struct_score.h:50
const char * description
Definition: struct_score.h:52
const char * shortname
Definition: struct_score.h:51
GCG_SCOREDATA * scoredata
Definition: struct_score.h:55
GCG_CLASSIFIERDATA * clsdata
Definition: struct_gcg.h:55
interface data structure for the detector calling methods
gcg::PARTIALDECOMP ** newpartialdecs
gcg::PARTIALDECOMP * workonpartialdec
gcg::DETPROBDATA * detprobdata
PARTIALDECOMP * partialdectowrite
SCIP_CLOCK * scoreclock
SCIP_Bool bendersonlycontsubpr
SCIP_Bool enableorigclassification
SCIP_Bool detectbenders
SCIP_CLOCK * completedetectionclock
SCIP_Bool hasrunoriginal
SCIP_Bool bendersonlybinmaster
GCG_VARCLASSIFIER ** varclassifiers
std::vector< int > * userblocknrcandidates
int maxnclassesperpartitionforlargeprobs
GCG_CONSCLASSIFIER ** consclassifiers
GCG_DETECTOR ** postprocessingdetectors
int weightinggpresolvedoriginaldecomps
GCG_SCORE ** scores
int * consclassifierpriorities
int maxnclassesfornblockcandidates
std::unordered_map< int, PARTIALDECOMP * > * partialdecsbyid
SCIP_Bool blocknumbercandsmedianvarspercons
SCIP_Bool enableorigdetection
SCIP_CLOCK * detectorclock
SCIP_Bool consnamesalreadyrepaired
gcg::DETPROBDATA * detprobdataorig
SCIP_Bool allowpartitionduplicates
SCIP_Bool postprocess
GCG_DETECTOR ** detectors
gcg::DETPROBDATA * detprobdatapres
int * varclassifierpriorities
std::vector< PARTIALDECOMP * > * partialdecs
GCG_DETECTOR ** propagatingdetectors
GCG_DETECTOR ** finishingdetectors
GCG_DECOMP ** decomps
data structures for constraint classifiers
structure information for decomposition information in GCG projects
data structures for score
data structures for variable classifiers
bool operator()(const std::pair< PARTIALDECOMP *, SCIP_Real > &left, const std::pair< PARTIALDECOMP *, SCIP_Real > &right)
#define GCG_DECL_CONSCLASSIFY(x)
#define GCG_DECL_FREECONSCLASSIFIER(x)
@ GCG_DECMODE_ORIGINAL
Definition: type_decomp.h:64
@ 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
#define GCG_DECL_INITDETECTOR(x)
Definition: type_detector.h:72
struct Partialdec_Detection_Data PARTIALDEC_DETECTION_DATA
Definition: type_detector.h:53
#define GCG_DECL_SETPARAMFAST(x)
#define GCG_DECL_SETPARAMDEFAULT(x)
#define GCG_DECL_EXITDETECTOR(x)
Definition: type_detector.h:82
#define GCG_DECL_SETPARAMAGGRESSIVE(x)
#define GCG_DECL_POSTPROCESSPARTIALDEC(x)
#define GCG_DECL_FINISHPARTIALDEC(x)
SCIP_VERBLEVEL_DIALOG
SCIP_VERBLEVEL_HIGH
SCIP_VERBLEVEL_NORMAL
SCIP_VERBLEVEL_FULL
SCIP_PARAMSETTING_OFF
SCIP_PARAMSETTING_AGGRESSIVE
SCIP_PARAMSETTING_DEFAULT
SCIP_PARAMSETTING_FAST
enum SCIP_ParamSetting SCIP_PARAMSETTING
SCIP_Result
SCIP_DIDNOTRUN
SCIP_FEASIBLE
SCIP_DIDNOTFIND
SCIP_SUCCESS
enum SCIP_Result SCIP_RESULT
SCIP_Retcode
SCIP_INVALIDDATA
SCIP_OKAY
SCIP_ERROR
enum SCIP_Retcode SCIP_RETCODE
#define GCG_DECL_SCOREFREE(x)
Definition: type_score.h:55
#define GCG_DECL_SCORECALC(x)
Definition: type_score.h:66
SCIP_STAGE_PROBLEM
SCIP_STAGE_TRANSFORMED
SCIP_STAGE_INIT
SCIP_STAGE_PRESOLVED
#define GCG_DECL_FREEVARCLASSIFIER(x)
#define GCG_DECL_VARCLASSIFY(x)