GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
dec_connectedbase.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_connectedbase.cpp
30 *
31 * @brief detector connectedbase (completes the partialdec by bfs)
32 * @author Martin Bergner
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
38#include "gcg/cons_decomp.h"
39#include "gcg/gcg.h"
42#include "scip/scip.h"
43#include "gcg/scip_misc.h"
44#include "scip/clock.h"
45#include <iostream>
46#include <algorithm>
47#include <vector>
48#include <queue>
49
50/* constraint handler properties */
51#define DEC_NAME "connectedbase" /**< name of detector */
52#define DEC_DESC "detector connectedbase" /**< description of detector*/
53#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 */
54#define DEC_MAXCALLROUND INT_MAX /** last round the detector gets called */
55#define DEC_MINCALLROUND 0 /** first round the detector gets called */
56#define DEC_PRIORITY 0 /**< priority of the constraint handler for separation */
57#define DEC_FREQCALLROUNDORIGINAL 1 /** frequency the detector gets called in detection loop while detecting the original problem */
58#define DEC_MAXCALLROUNDORIGINAL INT_MAX /** last round the detector gets called while detecting the original problem */
59#define DEC_MINCALLROUNDORIGINAL 0 /** first round the detector gets called while detecting the original problem */
60#define DEC_DECCHAR 'C' /**< display character of detector */
61#define DEC_ENABLED FALSE /**< should the detection be enabled */
62#define DEC_ENABLEDFINISHING TRUE /**< should the finishing be enabled */
63#define DEC_ENABLEDPOSTPROCESSING FALSE /**< should the finishing be enabled */
64#define DEC_SKIP FALSE /**< should detector be skipped if other detectors found decompositions */
65#define DEC_USEFULRECALL FALSE /**< is it useful to call this detector on a descendant of the propagated partialdec */
66#define DEFAULT_USECONSSADJ TRUE
67/*
68 * Data structures
69 */
70
71/** @todo fill in the necessary detector data */
72
73/** detector handler data */
75{
77};
78
79
80/*
81 * Local methods
82 */
83
84/* put your local methods here, and declare them static */
85
86
87/*
88 * detector callback methods
89 */
90
91/** destructor of detector to free user data (called when GCG is exiting) */
92/** destructor of detector to free detector data (called when SCIP is exiting) */
93static
94GCG_DECL_FREEDETECTOR(freeConnectedbase)
95{ /*lint --e{715}*/
96 GCG_DETECTORDATA *detectordata;
97 assert(detector != NULL);
98
99 assert(strcmp(GCGdetectorGetName(detector), DEC_NAME) == 0);
100
101 detectordata = GCGdetectorGetData(detector);
102 assert(detectordata != NULL);
103
104 SCIPfreeMemory(GCGgetOrigprob(gcg), &detectordata);
105
106 return SCIP_OKAY;
107}
108
109
110/** destructor of detector to free detector data (called before the solving process begins) */
111#define exitConnectedbase NULL
112
113/** detection initialization function of detector (called before solving is about to begin) */
114#define initConnectedbase NULL
115
116#define propagatePartialdecConnectedbase NULL
117
118
119static
120GCG_DECL_FINISHPARTIALDEC(finishPartialdecConnectedbase)
121{
123
124 SCIP_CLOCK* temporaryClock;
125 char decinfo[SCIP_MAXSTRLEN];
126
127 SCIP_Bool byconssadj;
128
129 gcg::PARTIALDECOMP* partialdec = partialdecdetectiondata->workonpartialdec;
130 gcg::DETPROBDATA* detprobdata = partialdecdetectiondata->detprobdata;
132 assert(origprob != NULL);
133 assert(partialdecdetectiondata->workonpartialdec->getDetprobdata() == detprobdata);
134
135 SCIPgetBoolParam(origprob, "detection/detectors/connectedbase/useconssadj", &byconssadj);
136
137 if ( byconssadj && !detprobdata->isConssAdjInitialized() )
138 detprobdata->createConssAdjacency();
139
140 SCIP_CALL_ABORT(SCIPcreateClock(origprob, &temporaryClock) );
141 SCIP_CALL_ABORT( SCIPstartClock(origprob, temporaryClock) );
142
143 //complete the partialdec by bfs
144 if( byconssadj && partialdec->getNLinkingvars() == 0 )
146 else
147 partialdec->completeByConnected();
148
149 SCIP_CALL_ABORT( SCIPstopClock(origprob, temporaryClock) );
150
151 partialdecdetectiondata->detectiontime = SCIPgetClockTime(origprob, temporaryClock);
152 SCIP_CALL( SCIPallocMemoryArray(origprob, &(partialdecdetectiondata->newpartialdecs), 1) );
153 partialdecdetectiondata->newpartialdecs[0] = partialdec;
154 partialdecdetectiondata->nnewpartialdecs = 1;
155 (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, "connected");
156 partialdecdetectiondata->newpartialdecs[0]->addDetectorChainInfo(decinfo);
157
158 partialdecdetectiondata->newpartialdecs[0]->addClockTime( SCIPgetClockTime(origprob, temporaryClock) );
159 SCIP_CALL_ABORT(SCIPfreeClock(origprob, &temporaryClock) );
160 // we used the provided partialdec -> prevent deletion
161 partialdecdetectiondata->workonpartialdec = NULL;
162
164
165 return SCIP_OKAY;
166}
167
168
169#define detectorPostprocessPartialdecConnectedbase NULL
170
171
172static
173GCG_DECL_SETPARAMAGGRESSIVE(setParamAggressiveConnectedbase)
174{
175 char setstr[SCIP_MAXSTRLEN];
176 const char* name = GCGdetectorGetName(detector);
178 assert(origprob != NULL);
179
180 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
182
183
184 return SCIP_OKAY;
185
186}
187
188
189static
190GCG_DECL_SETPARAMDEFAULT(setParamDefaultConnectedbase)
191{
192 char setstr[SCIP_MAXSTRLEN];
193 const char* name = GCGdetectorGetName(detector);
195 assert(origprob != NULL);
196
197 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
199
200 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
202
203 return SCIP_OKAY;
204
205}
206
207
208static
209GCG_DECL_SETPARAMFAST(setParamFastConnectedbase)
210{
211 char setstr[SCIP_MAXSTRLEN];
212 const char* name = GCGdetectorGetName(detector);
214 assert(origprob != NULL);
215
216 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
218
219 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
221
222 return SCIP_OKAY;
223
224}
225
226
227/*
228 * detector specific interface methods
229 */
230
231/** creates the handler for connectedbase detector and includes it in SCIP */
233 GCG* gcg /**< GCG data structure */
234 )
235{
236 GCG_DETECTORDATA* detectordata;
238 assert(origprob != NULL);
239
240 /**@todo create connectedbase detector data here*/
241 detectordata = NULL;
242 SCIP_CALL( SCIPallocMemory(origprob, &detectordata) );
243 assert(detectordata != NULL);
244
245 detectordata->useconssadj = TRUE;
246
248
249 /* add consname detector parameters */
250 /**@todo add connectedbase detector parameters */
251 SCIP_CALL( SCIPaddBoolParam(origprob, "detection/detectors/connectedbase/useconssadj", "should the constraint adjacency be used", &detectordata->useconssadj, FALSE, DEFAULT_USECONSSADJ, NULL, NULL) );
252
253 return SCIP_OKAY;
254}
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
GCG_EXPORT void createConssAdjacency()
create the constraint adjacency datastructure that is used (if created) for some methods to faster ac...
GCG_EXPORT SCIP_Bool isConssAdjInitialized()
determines whether or not the constraint-constraint adjacency data structure is initilized
class to manage partial decompositions
GCG_EXPORT void completeByConnectedConssAdjacency()
assigns all open constraints and open variables
GCG_EXPORT void completeByConnected()
assigns all open constraints and open variables
GCG_EXPORT int getNLinkingvars()
Gets size of the vector containing linking vars.
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
#define propagatePartialdecConnectedbase
#define detectorPostprocessPartialdecConnectedbase
#define exitConnectedbase
SCIP_RETCODE GCGincludeDetectorConnectedbase(GCG *gcg)
#define initConnectedbase
#define DEFAULT_USECONSSADJ
connectedbase detector
#define SCIP_MAXSTRLEN
#define SCIP_Bool
#define SCIP_CALL_ABORT(x)
#define TRUE
#define FALSE
GCG interface methods.
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *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 SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
#define SCIPallocMemoryArray(scip, ptr, num)
#define SCIPallocMemory(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)
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
#define NULL
various SCIP helper methods
struct SCIP_Clock SCIP_CLOCK
#define GCG_DECL_FREEDETECTOR(x)
#define GCG_DECL_SETPARAMFAST(x)
#define GCG_DECL_SETPARAMDEFAULT(x)
#define GCG_DECL_SETPARAMAGGRESSIVE(x)
#define GCG_DECL_FINISHPARTIALDEC(x)
struct GCG_DetectorData GCG_DETECTORDATA
struct Gcg GCG
Definition type_gcg.h:44
SCIP_DIDNOTFIND
SCIP_SUCCESS
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP