GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
dec_staircase_lsp.cpp
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* GCG --- Generic Column Generation */
5/* a Dantzig-Wolfe decomposition based extension */
6/* of the branch-cut-and-price framework */
7/* SCIP --- Solving Constraint Integer Programs */
8/* */
9/* Copyright (C) 2010-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
29/**@file dec_staircase_lsp.cpp
30 *
31 * @brief detector for staircase_lsp matrices
32 * @author Martin Bergner
33 * @author Michael Bastubbe
34 *
35 * This detector detects staircase_lsp structures in the constraint matrix by searching for the longest shortest path
36 * in the row graph of the matrix.
37 *
38 */
39
40/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
41
42#include <assert.h>
43#include <string.h>
44#include <iostream>
45
46
48#include "gcg/cons_decomp.h"
49#include "gcg/scip_misc.h"
50#include "gcg/pub_decomp.h"
51#include "tclique/tclique.h"
54#include "scip/clock.h"
55
56
57/* constraint handler properties */
58#define DEC_NAME "staircase_lsp" /**< name of detector */
59#define DEC_DESC "Staircase detection via shortest paths" /**< description of detector */
60#define DEC_PRIORITY 200 /**< priority of the detector */
61#define DEC_FREQCALLROUND 1 /**< frequency the detector gets called in detection loop ,ie it is called in round r if and only if minCallRound <= r <= maxCallRound AND (r - minCallRound) mod freqCallRound == 0 */
62#define DEC_MAXCALLROUND INT_MAX /**< last round the detector gets called */
63#define DEC_MINCALLROUND 0 /**< first round the detector gets called */
64#define DEC_FREQCALLROUNDORIGINAL 1 /**< frequency the detector gets called in detection loop while detecting the original problem */
65#define DEC_MAXCALLROUNDORIGINAL INT_MAX /**< last round the detector gets called while detecting the original problem */
66#define DEC_MINCALLROUNDORIGINAL 0 /**< first round the detector gets called while detecting the original problem */
67#define DEC_DECCHAR 'S' /**< display character of detector */
68#define DEC_ENABLED FALSE /**< should the detection be enabled */
69#define DEC_ENABLEDFINISHING FALSE /**< should the finishing be enabled */
70#define DEC_ENABLEDPOSTPROCESSING FALSE /**< should the postprocessing be enabled */
71#define DEC_SKIP FALSE /**< should detector be skipped if others found detections */
72#define DEC_USEFULRECALL FALSE /**< is it useful to call this detector on a descendant of the propagated partialdec */
73
74#define TCLIQUE_CALL(x) do \
75 { \
76 if((x) != TRUE ) \
77 { \
78 SCIPerrorMessage("Error in function call\n"); \
79 return SCIP_ERROR; \
80 } \
81 } \
82 while( FALSE )
83
84/*
85 * Data structures
86 */
87
88/** constraint handler data */
90{
97 std::vector<int>* oldToNew;
98 std::vector<int>* newToOld;
99};
100
101
102/*
103 * Local methods
104 */
105
106/* put your local methods here, and declare them static */
107
108
109/** creates the graph from the constraint matrix */
110static
112 SCIP* scip, /**< SCIP data structure */
113 TCLIQUE_GRAPH** graph, /**< Graph data structure */
114 gcg::PARTIALDECOMP* partialdec, /**< partial decomposition to use for matrix */
115 gcg::DETPROBDATA* detprobdata, /**< detection process information and data */
116 GCG_DETECTORDATA* detectordata /**< detector data data structure */
117 )
118{
119 int i;
120 int v;
121
122 assert(scip != NULL);
123 assert(graph != NULL);
124
125 TCLIQUE_CALL( tcliqueCreate(graph) );
126 assert(*graph != NULL);
127
128 if(detectordata->newToOld != NULL)
129 delete detectordata->newToOld;
130 if(detectordata->oldToNew != NULL)
131 delete detectordata->oldToNew;
132
133 detectordata->oldToNew = new std::vector<int>(detprobdata->getNConss(), -1) ;
134 detectordata->newToOld = new std::vector<int>(partialdec->getNOpenconss(), -1) ;
135
136 for( i = 0; i < partialdec->getNOpenconss(); ++i )
137 {
138 int cons = partialdec->getOpenconss()[i];
139 detectordata->oldToNew->at(cons) = i;
140 detectordata->newToOld->at(i) = cons;
141 TCLIQUE_CALL( tcliqueAddNode(*graph, i, 0) );
142 }
143
144 std::vector<bool> alreadyConsidered(detprobdata->getNConss(), false );
145
146
147 for( i = 0; i < partialdec->getNOpenconss(); ++i )
148 {
149 int cons = partialdec->getOpenconss()[i];
150 std::vector<int> neighborNodes(0);
151 std::vector<bool> isNeighbor(detprobdata->getNConss(), false);
152
153 alreadyConsidered[cons] = true;
154
155 for( v = 0; v < detprobdata->getNVarsForCons(cons ) ; ++v )
156 {
157 int var = detprobdata->getVarsForCons(cons)[v];
158
159 if(!partialdec->isVarOpenvar(var) )
160 continue;
161
162 for( int c = 0; c < detprobdata->getNConssForVar(var); ++c )
163 {
164 int otherCons = detprobdata->getConssForVar(var)[c];
165 if( isNeighbor[otherCons] || alreadyConsidered[otherCons] || !partialdec->isConsOpencons(otherCons) )
166 continue;
167 isNeighbor[otherCons] = true;
168
169 TCLIQUE_CALL( tcliqueAddEdge(*graph, detectordata->oldToNew->at(cons), detectordata->oldToNew->at(otherCons)) );
170 }
171 }
172 }
173
174 TCLIQUE_CALL( tcliqueFlush(*graph) );
175 /*SCIPdebug(tcliquePrintGraph(*graph));*/
176
177 return SCIP_OKAY;
178}
179
180
181
182
183/** finds the diameter of a connected component of a graph and computes all distances from some vertex of maximum eccentricity to all other vertices */
184static
186 SCIP* scip, /**< SCIP data structure */
187 GCG_DETECTORDATA* detectordata, /**< constraint handler data structure */
188 int* maxdistance, /**< diameter of the graph */
189 int* ncomp, /**< number of vertices the component contains */
190 int* vertices, /**< vertices of the connected component (ordered by BFS) */
191 int* distances, /**< distances of vertices to some vertex of maximum eccentricity */
192 int component /**< connected component to investigate */
193)
194{
195 TCLIQUE_GRAPH* graph;
196 int diameter = -1;
197 int* queue = NULL; /* queue, first entry is queue[squeue], last entry is queue[equeue] */
198 int squeue; /* index of first entry of the queue */
199 int equeue; /* index of last entry of the queue */
200 int nnodes; /* number of vertices the graph contains */
201 int ncompnodes = 0; /* number of vertices the component contains */
202 SCIP_Bool* marked = NULL;
203 int* eccentricity = NULL; /* upper bounds on the eccentricities */
204 int* dist = NULL; /* distances from some start vertex to all other vertices (gets updated in each BFS) */
205 int* origdegree = NULL; /* degrees of the vertices */
206 int* degree = NULL; /* degrees of the vertices sorted in decreasing order */
207 int* degreepos = NULL;
208 int i;
209 int j;
210 int k = 50; /* number of low-degree vertices that are visited before high-degree vertices are visited */
211
212 /* This method computes the diameter of a connected component by starting BFS at each vertex and memorizing the depth of the search tree.
213 * If a tree has greater depth than any other tree that was computed before, the vertices itself and their distances to the root of the
214 * tree are stored in 'vertices' and 'distances', respectively.
215 *
216 * As these steps require $O(nm)$ time in the worst case, we apply a simple heuristic that stops BFS from vertices that do not have
217 * maximum eccentricity, and in some cases it even prevents starting BFS at such vertices.
218 * a) For each vertex 'v' there is an upper bound 'eccentricity[v]' on the actual eccentricity of 'v'. Initially, this is set to a very large number.
219 * b) Whenever a BFS with root 'v' has finished, 'eccentricity[v]' contains the actual eccentricity of 'v'.
220 * c) If during a BFS with root 'v' a vertex 'u' is discovered, then dist(v, u) + eccentricty[u] is an upper bound on the eccentricity of 'v',
221 * and therefore the BFS is stopped if dist(v, u) + eccentricity[u] <= diameter_lb, where diameter_lb is the greatest eccentricity known so far.
222 */
223
224 assert(scip != NULL);
225 assert(detectordata != NULL);
226 assert(detectordata->graph != NULL);
227 assert(detectordata->components != NULL);
228 assert(maxdistance != NULL);
229 assert(vertices != NULL);
230 assert(distances != NULL);
231 assert(ncomp != NULL);
232
233 graph = detectordata->graph;
234 nnodes = tcliqueGetNNodes(graph);
235
238 SCIP_CALL( SCIPallocMemoryArray(scip, &eccentricity, nnodes) );
241 SCIP_CALL( SCIPallocMemoryArray(scip, &degreepos, nnodes) );
242
243 /* get degrees of vertices and initialize all eccentricities of vertices to values representing upper bounds */
244 origdegree = tcliqueGetDegrees(graph);
245 for( i = 0; i < nnodes; ++i )
246 {
247 if( detectordata->components[i] != component )
248 continue;
249
250 eccentricity[i] = 2 * nnodes; /* do not use INT_MAX because it could lead to an overflow when adding values */
251 degree[ncompnodes] = origdegree[i]; /* we copy the degree array because we are going to sort it */
252 degreepos[ncompnodes] = i;
253
254 ++ncompnodes;
255 }
256
257 /* sort vertices by their degrees in decreasing order */
258 SCIPsortDownIntInt(degree, degreepos, ncompnodes);
259
260 if( ncompnodes < k )
261 k = ncompnodes;
262
263 /* for each vertex a BFS will be performed */
264 for( j = 0; j < ncompnodes; j++ )
265 {
266 int eccent = 0; /* eccentricity of this vertex, only valid if vertex has not been pruned */
267 int startnode;
268 SCIP_Bool pruned = FALSE;
269
270 /* change order in which BFSes are performed: first start at 'k' low-degree vertices, then start BFS at high-degree vertices */
271 if(j < k)
272 startnode = degreepos[ncompnodes - k + j];
273 else
274 startnode = degreepos[j - k];
275
276 /* eccentricity[startnode] always represents an UPPER BOUND on the actual eccentricity! */
277 if( eccentricity[startnode] <= diameter )
278 continue;
279
280 /* unmark all vertices */
282
283 /* add 'startnode' to the queue */
284 queue[0] = startnode;
285 equeue = 1;
286 squeue = 0;
287 marked[startnode] = TRUE;
288 dist[startnode] = 0;
289
290 /* continue BFS until vertex gets pruned or all vertices have been visited */
291 while( !pruned && (equeue > squeue) )
292 {
293 int currentnode;
294 int currentdistance;
295 int* lastneighbour;
296 int* node;
297
298 /* dequeue new node */
299 currentnode = queue[squeue];
300 currentdistance = dist[currentnode];
301 ++squeue;
302
303 lastneighbour = tcliqueGetLastAdjedge(graph, currentnode);
304 /* go through all neighbours */
305 for( node = tcliqueGetFirstAdjedge(graph, currentnode); !pruned && (node <= lastneighbour); ++node )
306 {
307 const int v = *node;
308 /* visit 'v' if it has not been visited yet */
309 if( !marked[v] )
310 {
311 /* mark 'v' and add it to the queue */
312 marked[v] = TRUE;
313 queue[equeue] = v;
314 dist[v] = currentdistance + 1;
315 ++equeue;
316
317 /* if 'v' is further away from the startnode than any other vertex, update the eccentricity */
318 if( dist[v] > eccent )
319 eccent = dist[v];
320
321 /* prune the startnode if its eccentricity will certainly not lead to a new upper bound */
322 if( eccentricity[v] + dist[v] <= diameter )
323 {
324 pruned = TRUE;
325 eccent = eccentricity[v] + dist[v];
326 }
327
328 /* update upper bound on eccentricity of 'v' */
329 /*if( eccentricity[currentnode] + dist[v] < eccentricity[v] )
330 eccentricity[v] = eccentricity[currentnode] + dist[v];*/
331 }
332 }
333 }
334
335 eccentricity[startnode] = eccent;
336
337 if( eccent > diameter )
338 {
339 SCIPdebugMessage("new incumbent in component %i: path of length %i starts at %i\n", component, eccent, startnode);
340 diameter = eccent;
341
342 *maxdistance = diameter;
343 *ncomp = ncompnodes;
344 /*detectordata->nblocks = diameter + 1;*/
345
346 for( i = 0; i < ncompnodes; ++i )
347 {
348 vertices[i] = queue[i];
349 distances[i] = dist[queue[i]];
350 }
351 }
352 }
353
354 SCIPfreeMemoryArray(scip, &degreepos);
355 SCIPfreeMemoryArray(scip, &degree);
357 SCIPfreeMemoryArray(scip, &eccentricity);
358 SCIPfreeMemoryArray(scip, &marked);
359 SCIPfreeMemoryArray(scip, &queue);
360
361 return SCIP_OKAY;
362}
363
364/** finds the connected components of the row graph. a staircase_lsp decomposition will be built for each component separately. */
365static
367 SCIP* scip, /**< SCIP data structure */
368 GCG_DETECTORDATA* detectordata /**< constraint handler data structure */
369 )
370{
371 int i;
372 int nnodes;
373 int ncomps = 0;
374 int curcomp;
375 int* queue = NULL;
376 int squeue;
377 int equeue;
378 TCLIQUE_GRAPH* graph;
379 int* component;
380
381 assert(scip != NULL);
382 assert(detectordata != NULL);
383 assert(detectordata->graph != NULL);
384 assert(tcliqueGetNNodes(detectordata->graph) >= 0);
385
386 graph = detectordata->graph;
387 nnodes = tcliqueGetNNodes(graph);
388
389 /* for each vertex the 'component' array contains a number from [0, ncomponents) */
390 assert(detectordata->components == NULL);
391 SCIP_CALL( SCIPallocMemoryArray(scip, &(detectordata->components), nnodes) );
392 component = detectordata->components;
393
394 /* component[i] == -1 if and only if vertex i has not been assigned to a component yet */
395 for( i = 0; i < nnodes; ++i )
396 component[i] = -1;
397
399
400 for( i = 0; i < nnodes; ++i )
401 {
402 /* find first node that has not been visited yet and start BFS */
403 if( component[i] >= 0 )
404 continue;
405
406 SCIPdebugMessage("found new component; starting at %i\n", i);
407 squeue = 0;
408 equeue = 1;
409 queue[0] = i;
410 curcomp = ncomps++;
411 component[i] = curcomp;
412
413 /* dequeue a vertex as long as the queue is not empty */
414 while( equeue > squeue )
415 {
416 int curnode;
417 int* lastneighbour;
418 int* node;
419
420 curnode = queue[squeue++];
421
422 assert(curnode < nnodes);
423
424 /* add unvisited neighbors of this vertex to the queue */
425 lastneighbour = tcliqueGetLastAdjedge(graph, curnode);
426 for( node = tcliqueGetFirstAdjedge(graph, curnode); node <= lastneighbour; ++node )
427 {
428 assert(*node < nnodes);
429
430 if( component[*node] < 0 )
431 {
432 assert(equeue < nnodes);
433 component[*node] = curcomp;
434 queue[equeue++] = *node;
435 }
436 }
437 }
438 }
439
440 detectordata->ncomponents = ncomps;
441 SCIPdebugMessage("found %i components\n", ncomps);
442
443 SCIPfreeMemoryArray(scip, &queue);
444 return SCIP_OKAY;
445}
446
447
448/** destructor of detector to free user data (called when GCG is exiting) */
449static
450GCG_DECL_FREEDETECTOR(detectorFreeStaircaseLsp)
451{ /*lint --e{715}*/
452 GCG_DETECTORDATA *detectordata;
453
454 assert(detector != NULL);
455
456 assert(strcmp(GCGdetectorGetName(detector), DEC_NAME) == 0);
457
458 detectordata = GCGdetectorGetData(detector);
459 assert(detectordata != NULL);
460
461 delete detectordata->newToOld;
462 delete detectordata->oldToNew;
463
464 SCIPfreeMemory(GCGgetOrigprob(gcg), &detectordata);
465
466 return SCIP_OKAY;
467}
468
469/** detector initialization method (called after the problem has been transformed) */
470static
471GCG_DECL_INITDETECTOR(detectorInitStaircaseLsp)
472{ /*lint --e{715}*/
473
474 GCG_DETECTORDATA *detectordata;
475
476 assert(detector != NULL);
477
478 assert(strcmp(GCGdetectorGetName(detector), DEC_NAME) == 0);
479
480 detectordata = GCGdetectorGetData(detector);
481 assert(detectordata != NULL);
482
483 detectordata->graph = NULL;
484 detectordata->components = NULL;
485 detectordata->ncomponents = 0;
486 detectordata->constoblock = NULL;
487 detectordata->vartoblock = NULL;
488 detectordata->nblocks = 0;
489
490 return SCIP_OKAY;
491}
492
493/** detector deinitialization method (called before the transformed problem is freed) */
494static
495GCG_DECL_EXITDETECTOR(detectorExitStaircaseLsp)
496{ /*lint --e{715}*/
497 GCG_DETECTORDATA *detectordata;
498
499 assert(detector != NULL);
500
501 assert(strcmp(GCGdetectorGetName(detector), DEC_NAME) == 0);
502
503 detectordata = GCGdetectorGetData(detector);
504 assert(detectordata != NULL);
505
506 if( detectordata->graph != NULL )
507 {
508 tcliqueFree(&detectordata->graph);
509 }
510
511 if( detectordata->components != NULL )
512 {
514 }
515
516 return SCIP_OKAY;
517}
518
519
520/** detection function for partialdecs */
521static
523 SCIP* scip, /**< SCIP data structure */
524 GCG_DETECTORDATA* detectordata, /**< detectordata of the detector */
525 Partialdec_Detection_Data* partialdecdetectiondata /**< partialdecdetectiondata (including the detprobdata) where to store the new Partialdecs */
526)
527{
528 int i;
529 int j;
530 int* nodes = NULL;
531 int nnodes;
532 int* distances = NULL;
533 int* blocks = NULL;
534 int nblocks = 0;
535
536 char decinfo[SCIP_MAXSTRLEN];
537
538 gcg::DETPROBDATA* detprobdata = partialdecdetectiondata->detprobdata;
539 gcg::PARTIALDECOMP* currpartialdec = new gcg::PARTIALDECOMP(partialdecdetectiondata->workonpartialdec);
540
541 SCIP_CLOCK* temporaryClock;
542 SCIP_CALL_ABORT(SCIPcreateClock(scip, &temporaryClock) );
543 SCIP_CALL_ABORT( SCIPstartClock(scip, temporaryClock) );
544
545 currpartialdec->refineToMaster();
546
547 currpartialdec->sort();
548
549 //currpartialdec->showScatterPlot(detprobdata);
550
551 //SCIPverbMessage(scip, SCIP_VERBLEVEL_NORMAL, NULL, "Detecting staircase structure:");
552
553 SCIP_CALL( createGraphFromPartialMatrix(scip, &(detectordata->graph), currpartialdec, detprobdata, detectordata) );
554 SCIP_CALL( SCIPhashmapCreate(&detectordata->constoblock, SCIPblkmem(scip), detprobdata->getNConss() ) );
555
556 if( tcliqueGetNNodes(detectordata->graph) > 0 )
557 {
558 nnodes = tcliqueGetNNodes(detectordata->graph);
559
560 /* find connected components of the graph. the result will be stored in 'detectordata->components' */
561 SCIP_CALL( findConnectedComponents(scip, detectordata) );
562
564 SCIP_CALL( SCIPallocMemoryArray(scip, &distances, nnodes) );
566
567 for( i = 0; i < nnodes; ++i)
568 blocks[i] = -1;
569
570 /* find the diameter of each connected component */
571 for( i = 0; i < detectordata->ncomponents; ++i )
572 {
573 int diameter = 0;
574 int ncompsize = 0;
575
576 SCIP_CALL( findDiameter(scip, detectordata, &diameter, &ncompsize, nodes, distances, i) );
577 SCIPdebugMessage("component %i has %i vertices and diameter %i\n", i, ncompsize, diameter);
578
579 for( j = 0; j < ncompsize; j++ )
580 {
581 assert(nodes[j] >= 0);
582 assert(nodes[j] < nnodes);
583 assert(distances[j] >= 0);
584 assert(distances[j] <= diameter);
585 assert(distances[j] + nblocks < nnodes);
586
587 blocks[nodes[j]] = nblocks + distances[j];
588 SCIPdebugMessage("\tnode %i to block %i\n", nodes[j], nblocks + distances[j]);
589 }
590
591 nblocks += (diameter + 1);
592 }
593 if( nblocks > 0 )
594 {
595 detectordata->nblocks = nblocks;
596
597 for( i = 0; i < nnodes; ++i )
598 {
599 assert(blocks[i] >= 0);
600 SCIP_CALL( SCIPhashmapInsert(detectordata->constoblock, (void*) (size_t) detectordata->newToOld->at(i), (void*) (size_t) (blocks[i] + 1)) );
601 }
602 }
603
604 SCIPfreeMemoryArray(scip, &blocks);
605 SCIPfreeMemoryArray(scip, &nodes);
606 SCIPfreeMemoryArray(scip, &distances);
607 SCIPfreeMemoryArray(scip, &(detectordata->components));
608 }
609
610 SCIP_CALL( currpartialdec->assignPartialdecFromConstoblock(detectordata->constoblock, nblocks) );
611
612 currpartialdec->assignCurrentStairlinking();
613 currpartialdec->prepare();
614
615 if( detectordata->constoblock != NULL )
616 SCIPhashmapFree(&detectordata->constoblock);
617 if( detectordata->vartoblock != NULL )
618 SCIPhashmapFree(&detectordata->vartoblock);
619
620 SCIP_CALL_ABORT( SCIPstopClock(scip, temporaryClock ) );
621
622 assert(currpartialdec->checkConsistency());
623
624 partialdecdetectiondata->detectiontime = SCIPgetClockTime(scip, temporaryClock);
625 SCIP_CALL( SCIPallocMemoryArray(scip, &(partialdecdetectiondata->newpartialdecs), 1) );
626 partialdecdetectiondata->newpartialdecs[0] = currpartialdec;
627 partialdecdetectiondata->nnewpartialdecs = 1;
628 (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, "staircase\\_lsp");
629 partialdecdetectiondata->newpartialdecs[0]->addDetectorChainInfo(decinfo);
630 partialdecdetectiondata->newpartialdecs[0]->addClockTime(SCIPgetClockTime(scip, temporaryClock));
631
632 tcliqueFree(&detectordata->graph);
633 SCIP_CALL_ABORT(SCIPfreeClock(scip, &temporaryClock) );
634
635 return SCIP_OKAY;
636}
637
638
639/** detector structure detection method, tries to detect a structure in the problem */
640static
641GCG_DECL_PROPAGATEPARTIALDEC(detectorPropagatePartialdecStaircaseLsp)
642{
643 GCG_DETECTORDATA* detectordata = NULL;
645
646 SCIP_CALL( SCIPallocMemory(origprob, &detectordata) );
647 assert(detectordata != NULL);
648 detectordata->graph = NULL;
649 detectordata->constoblock = NULL;
650 detectordata->vartoblock = NULL;
651 detectordata->nblocks = 0;
652 detectordata->newToOld = NULL;
653 detectordata->oldToNew = NULL;
654 detectordata->components = NULL;
655 detectordata->ncomponents = 0;
656
658
659 detection(origprob, detectordata, partialdecdetectiondata);
660
661 delete detectordata->newToOld;
662 delete detectordata->oldToNew;
663
664 SCIPfreeMemory(origprob, &detectordata);
665
667
668 return SCIP_OKAY;
669}
670
671static
672GCG_DECL_FINISHPARTIALDEC(detectorFinishPartialdecStaircaseLsp)
673{
674 GCG_DETECTORDATA* detectordata = NULL;
676
677 SCIP_CALL( SCIPallocMemory(origprob, &detectordata) );
678 assert(detectordata != NULL);
679 detectordata->graph = NULL;
680 detectordata->constoblock = NULL;
681 detectordata->vartoblock = NULL;
682 detectordata->nblocks = 0;
683 detectordata->newToOld = NULL;
684 detectordata->oldToNew = NULL;
685 detectordata->components = NULL;
686 detectordata->ncomponents = 0;
687
689
690 detection(origprob, detectordata, partialdecdetectiondata);
691
692 delete detectordata->newToOld;
693 delete detectordata->oldToNew;
694
695 SCIPfreeMemory(origprob, &detectordata);
696
698
699 return SCIP_OKAY;
700}
701//#define detectorExitStaircase NULL
702
703#define detectorPostprocessPartialdecStaircaseLsp NULL
704
705
706static
707GCG_DECL_SETPARAMFAST(setParamAggressiveStaircaseLsp)
708{
709 char setstr[SCIP_MAXSTRLEN];
710 const char* name = GCGdetectorGetName(detector);
712
713 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
715
716 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
718
719 return SCIP_OKAY;
720
721}
722
723static
724GCG_DECL_SETPARAMFAST(setParamDefaultStaircaseLsp)
725{
726 char setstr[SCIP_MAXSTRLEN];
727 const char* name = GCGdetectorGetName(detector);
729
730 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
732
733 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
735
736 return SCIP_OKAY;
737
738}
739
740
741
742static
743GCG_DECL_SETPARAMFAST(setParamFastStaircaseLsp)
744{
745 char setstr[SCIP_MAXSTRLEN];
746 const char* name = GCGdetectorGetName(detector);
748
749 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
751
752 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
754
755 return SCIP_OKAY;
756
757}
758
759
760/*
761 * constraint specific interface methods
762 */
763
764/** creates the handler for staircase constraints and includes it in SCIP */
766 GCG* gcg /**< GCG data structure */
767 )
768{
769 GCG_DETECTORDATA* detectordata;
770
771 /* for thread safety: create staircase constraint handler data in callback methods*/
772 detectordata = NULL;
773
774 SCIP_CALL( SCIPallocMemory(GCGgetOrigprob(gcg), &detectordata) );
775 assert(detectordata != NULL);
776 detectordata->graph = NULL;
777 detectordata->constoblock = NULL;
778 detectordata->vartoblock = NULL;
779 detectordata->nblocks = 0;
780 detectordata->newToOld = NULL;
781 detectordata->oldToNew = NULL;
782
783
786 DEC_USEFULRECALL, detectordata, detectorFreeStaircaseLsp,
787 detectorInitStaircaseLsp, detectorExitStaircaseLsp, detectorPropagatePartialdecStaircaseLsp, detectorFinishPartialdecStaircaseLsp, detectorPostprocessPartialdecStaircaseLsp, setParamAggressiveStaircaseLsp, setParamDefaultStaircaseLsp, setParamFastStaircaseLsp) );
788
789
790 return SCIP_OKAY;
791}
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
GCG_EXPORT std::vector< int > & getConssForVar(int varIndex)
returns the constraint indices of the coefficient matrix for a variable
GCG_EXPORT int getNConss()
returns the number of variables considered in the detprobdata
GCG_EXPORT int getNVarsForCons(int consIndex)
returns the number of variables for a given constraint
GCG_EXPORT int getNConssForVar(int varIndex)
returns the number of constraints for a given variable where the var has a nonzero entry in
GCG_EXPORT std::vector< int > & getVarsForCons(int consIndex)
returns the variable indices of the coefficient matrix for a constraint
class to manage partial decompositions
GCG_EXPORT void refineToMaster()
refine partialdec with focus on master
GCG_EXPORT bool checkConsistency()
Checks whether the assignments in the partialdec are consistent.
GCG_EXPORT void addDetectorChainInfo(const char *decinfo)
add information about the detector chain
GCG_EXPORT int getNOpenconss()
Gets size of vector containing constraints not assigned yet.
GCG_EXPORT bool isVarOpenvar(int var)
Checks whether the var is an open var.
GCG_EXPORT SCIP_RETCODE assignPartialdecFromConstoblock(SCIP_HASHMAP *constoblock, int additionalNBlocks)
assigns conss structure according to given hashmap
GCG_EXPORT void addClockTime(SCIP_Real clocktime)
adds detection time of one detector
GCG_EXPORT std::vector< int > & getOpenconss()
Gets vector containing constraints not assigned yet.
GCG_EXPORT bool isConsOpencons(int cons)
Gets whether the cons is an open cons.
GCG_EXPORT bool sort()
sorts the vars and conss data structures by their indices
GCG_EXPORT bool assignCurrentStairlinking()
assigns open vars to stairlinking if appropriate
const char * GCGdetectorGetName(GCG_DETECTOR *detector)
returns the name of the provided detector
GCG_DETECTORDATA * GCGdetectorGetData(GCG_DETECTOR *detector)
returns the data of the provided detector
SCIP_RETCODE GCGincludeDetector(GCG *gcg, const char *name, const char decchar, const char *description, int freqCallRound, int maxCallRound, int minCallRound, int freqCallRoundOriginal, int maxCallRoundOriginal, int minCallRoundOriginal, int priority, SCIP_Bool enabled, SCIP_Bool enabledFinishing, SCIP_Bool enabledPostprocessing, SCIP_Bool skip, SCIP_Bool usefulRecall, GCG_DETECTORDATA *detectordata, GCG_DECL_FREEDETECTOR((*freeDetector)), GCG_DECL_INITDETECTOR((*initDetector)), GCG_DECL_EXITDETECTOR((*exitDetector)), GCG_DECL_PROPAGATEPARTIALDEC((*propagatePartialdecDetector)), GCG_DECL_FINISHPARTIALDEC((*finishPartialdecDetector)), GCG_DECL_POSTPROCESSPARTIALDEC((*postprocessPartialdecDetector)), GCG_DECL_SETPARAMAGGRESSIVE((*setParamAggressiveDetector)), GCG_DECL_SETPARAMDEFAULT((*setParamDefaultDetector)),)
includes one detector
constraint handler for structure detection
#define DEC_MAXCALLROUND
#define DEC_MINCALLROUNDORIGINAL
#define DEC_ENABLEDFINISHING
#define DEC_ENABLED
#define DEC_DECCHAR
#define DEC_NAME
#define DEC_MINCALLROUND
#define DEC_ENABLEDPOSTPROCESSING
#define DEC_DESC
#define DEC_FREQCALLROUND
#define DEC_PRIORITY
#define DEC_USEFULRECALL
#define DEC_SKIP
#define DEC_MAXCALLROUNDORIGINAL
#define DEC_FREQCALLROUNDORIGINAL
static SCIP_RETCODE detection(SCIP *scip, Partialdec_Detection_Data *partialdecdetectiondata)
static SCIP_RETCODE findDiameter(SCIP *scip, GCG_DETECTORDATA *detectordata, int *maxdistance, int *ncomp, int *vertices, int *distances, int component)
static SCIP_RETCODE createGraphFromPartialMatrix(SCIP *scip, TCLIQUE_GRAPH **graph, gcg::PARTIALDECOMP *partialdec, gcg::DETPROBDATA *detprobdata, GCG_DETECTORDATA *detectordata)
#define TCLIQUE_CALL(x)
SCIP_RETCODE GCGincludeDetectorStaircaseLsp(GCG *gcg)
static SCIP_RETCODE findConnectedComponents(SCIP *scip, GCG_DETECTORDATA *detectordata)
#define detectorPostprocessPartialdecStaircaseLsp
staircase compontent detector
#define SCIP_MAXSTRLEN
#define SCIP_Bool
#define SCIP_CALL_ABORT(x)
#define TRUE
#define FALSE
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPallocMemoryArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeMemoryArray(scip, ptr)
SCIP_RETCODE SCIPcreateClock(SCIP *scip, SCIP_CLOCK **clck)
SCIP_RETCODE SCIPstopClock(SCIP *scip, SCIP_CLOCK *clck)
SCIP_RETCODE SCIPfreeClock(SCIP *scip, SCIP_CLOCK **clck)
SCIP_Real SCIPgetClockTime(SCIP *scip, SCIP_CLOCK *clck)
SCIP_RETCODE SCIPstartClock(SCIP *scip, SCIP_CLOCK *clck)
void SCIPsortDownIntInt(int *intarray1, int *intarray2, int len)
int SCIPsnprintf(char *t, int len, const char *s,...)
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
* result
SCIP_VAR * var
int j
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
SCIP_Longint nnodes
#define NULL
#define BMSclearMemoryArray(ptr, num)
public methods for working with decomposition structures
various SCIP helper methods
TCLIQUE_GRAPH * graph
std::vector< int > * newToOld
std::vector< int > * oldToNew
SCIP_HASHMAP * vartoblock
SCIP_HASHMAP * constoblock
interface data structure for the detector calling methods
gcg::PARTIALDECOMP ** newpartialdecs
gcg::PARTIALDECOMP * workonpartialdec
gcg::DETPROBDATA * detprobdata
int * tcliqueGetLastAdjedge(TCLIQUE_GRAPH *tcliquegraph, int node)
int * tcliqueGetDegrees(TCLIQUE_GRAPH *tcliquegraph)
void tcliqueFree(TCLIQUE_GRAPH **tcliquegraph)
int * tcliqueGetFirstAdjedge(TCLIQUE_GRAPH *tcliquegraph, int node)
TCLIQUE_Bool tcliqueFlush(TCLIQUE_GRAPH *tcliquegraph)
struct TCLIQUE_Graph TCLIQUE_GRAPH
TCLIQUE_Bool tcliqueCreate(TCLIQUE_GRAPH **tcliquegraph)
TCLIQUE_Bool tcliqueAddNode(TCLIQUE_GRAPH *tcliquegraph, int node, TCLIQUE_WEIGHT weight)
TCLIQUE_Bool tcliqueAddEdge(TCLIQUE_GRAPH *tcliquegraph, int node1, int node2)
struct SCIP_Clock SCIP_CLOCK
#define GCG_DECL_FREEDETECTOR(x)
#define GCG_DECL_INITDETECTOR(x)
#define GCG_DECL_SETPARAMFAST(x)
#define GCG_DECL_EXITDETECTOR(x)
#define GCG_DECL_FINISHPARTIALDEC(x)
#define GCG_DECL_PROPAGATEPARTIALDEC(x)
struct GCG_DetectorData GCG_DETECTORDATA
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_HashMap SCIP_HASHMAP
SCIP_DIDNOTFIND
SCIP_SUCCESS
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP