Scippy

GCG

Branch-and-Price & Column Generation for Everyone

dec_compgreedily.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_compgreedily.cpp
30 *
31 * @brief detector compgreedily (assigns the open cons and open vars of the partialdec greedily)
32 * @author Michael Bastubbe
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
38#include "gcg/cons_decomp.h"
41#include "scip/clock.h"
42#include <iostream>
43
44/* constraint handler properties */
45#define DEC_NAME "compgreedily" /**< name of detector */
46#define DEC_DESC "detector compgreedily" /**< description of detector*/
47#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 */
48#define DEC_MAXCALLROUND INT_MAX /** last round the detector gets called */
49#define DEC_MINCALLROUND 0 /** first round the detector gets called */
50#define DEC_FREQCALLROUNDORIGINAL 1 /** frequency the detector gets called in detection loop while detecting the original problem */
51#define DEC_MAXCALLROUNDORIGINAL INT_MAX /** last round the detector gets called while detecting the original problem */
52#define DEC_MINCALLROUNDORIGINAL 0 /** first round the detector gets called while detecting the original problem */
53#define DEC_PRIORITY 0 /**< priority of the constraint handler for separation */
54#define DEC_DECCHAR 'g' /**< display character of detector */
55#define DEC_ENABLED FALSE /**< should the detection be enabled */
56#define DEC_ENABLEDFINISHING FALSE /**< should the finishing be enabled */
57#define DEC_ENABLEDPOSTPROCESSING FALSE /**< should the finishing be enabled */
58#define DEC_SKIP FALSE /**< should detector be skipped if other detectors found decompositions */
59#define DEC_USEFULRECALL FALSE /**< is it useful to call this detector on a descendant of the propagated partialdec */
60
61/** parameter limits for emphasis default */
62
63#define DEFAULT_LIMITHALFPERIMETERENABLEDFINISHING 20000 /** limit in terms of nrows + ncols for enabling finishing */
64#define DEFAULT_LIMITHALFPERIMETERENABLEDORIGINAL 10000 /** limit in terms of nrows + ncols for enabling in detecting for unpresolved problem */
65
66
67/*
68 * Data structures
69 */
70
71/** @todo fill in the necessary detector data */
72
73/** detector handler data */
75{
76};
77
78
79/*
80 * Local methods
81 */
82
83/* put your local methods here, and declare them static */
84
85/*
86 * detector callback methods
87 */
88
89/** destructor of detector to free user data (called when GCG is exiting) */
90
91#define freeCompgreedily NULL
92
93/** destructor of detector to free detector data (called before the solving process begins) */
94
95#define exitCompgreedily NULL
96
97#define initCompgreedily NULL
98
99static
100GCG_DECL_PROPAGATEPARTIALDEC(propagatePartialdecCompgreedily)
101{
102 SCIP* origprob = GCGgetOrigprob(gcg);
103 *result = SCIP_DIDNOTFIND;
104
105 char decinfo[SCIP_MAXSTRLEN];
106 SCIP_CLOCK* temporaryClock;
107 SCIP_CALL_ABORT( SCIPcreateClock(origprob, &temporaryClock) );
108 SCIP_CALL_ABORT( SCIPstartClock(origprob, temporaryClock) );
109
110 gcg::PARTIALDECOMP* partialdec = partialdecdetectiondata->workonpartialdec;
111
112 //assign open conss and vars greedily
113 partialdec->completeGreedily();
114
115 SCIP_CALL_ABORT( SCIPstopClock(origprob, temporaryClock) );
116
117 partialdecdetectiondata->detectiontime = SCIPgetClockTime(origprob, temporaryClock);
118 SCIP_CALL( SCIPallocMemoryArray(origprob, &(partialdecdetectiondata->newpartialdecs), 1) );
119 partialdecdetectiondata->newpartialdecs[0] = partialdec;
120 partialdecdetectiondata->nnewpartialdecs = 1;
121
122 partialdecdetectiondata->newpartialdecs[0]->addClockTime(SCIPgetClockTime(origprob, temporaryClock));
123 SCIP_CALL_ABORT(SCIPfreeClock(origprob, &temporaryClock) );
124 (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, "compgreed");
125 partialdecdetectiondata->newpartialdecs[0]->addDetectorChainInfo(decinfo);
126 // we used the provided partialdec -> prevent deletion
127 partialdecdetectiondata->workonpartialdec = NULL;
128
129 *result = SCIP_SUCCESS;
130
131 return SCIP_OKAY;
132}
133
134static
135GCG_DECL_FINISHPARTIALDEC(finishPartialdecCompgreedily)
136{
137 SCIP* origprob = GCGgetOrigprob(gcg);
138 *result = SCIP_DIDNOTFIND;
139 char decinfo[SCIP_MAXSTRLEN];
140
141 SCIP_CLOCK* temporaryClock;
142 SCIP_CALL_ABORT (SCIPcreateClock(origprob, &temporaryClock) );
143 SCIP_CALL_ABORT( SCIPstartClock(origprob, temporaryClock) );
144
145 gcg::PARTIALDECOMP* partialdec = partialdecdetectiondata->workonpartialdec;
146
147 //assign open conss and vars greedily
148 partialdec->completeGreedily();
149
150 SCIP_CALL_ABORT( SCIPstopClock(origprob, temporaryClock) );
151
152 partialdecdetectiondata->detectiontime = SCIPgetClockTime(origprob, temporaryClock);
153 SCIP_CALL( SCIPallocMemoryArray(origprob, &(partialdecdetectiondata->newpartialdecs), 1) );
154 partialdecdetectiondata->newpartialdecs[0] = partialdec;
155 partialdecdetectiondata->nnewpartialdecs = 1;
156 (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, "compgreed");
157 partialdecdetectiondata->newpartialdecs[0]->addDetectorChainInfo(decinfo);
158 partialdecdetectiondata->newpartialdecs[0]->addClockTime(SCIPgetClockTime(origprob, temporaryClock));
159 // we used the provided partialdec -> prevent deletion
160 partialdecdetectiondata->workonpartialdec = NULL;
161
162 SCIP_CALL_ABORT(SCIPfreeClock(origprob, &temporaryClock) );
163
164 *result = SCIP_SUCCESS;
165
166 return SCIP_OKAY;
167}
168
169#define detectorPostprocessPartialdecCompgreedily NULL
170
171
172static
173GCG_DECL_SETPARAMAGGRESSIVE(setParamAggressiveCompgreedily)
174{
175 char setstr[SCIP_MAXSTRLEN];
176 const char* name = GCGdetectorGetName(detector);
177 SCIP* origprob = GCGgetOrigprob(gcg);
178
179 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
180 SCIP_CALL( SCIPsetBoolParam(origprob, setstr, FALSE) );
181
182 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
183 SCIP_CALL( SCIPsetBoolParam(origprob, setstr, FALSE ) );
184
185 return SCIP_OKAY;
186}
187
188
189static
190GCG_DECL_SETPARAMDEFAULT(setParamDefaultCompgreedily)
191{
192 char setstr[SCIP_MAXSTRLEN];
193 const char* name = GCGdetectorGetName(detector);
194 SCIP* origprob = GCGgetOrigprob(gcg);
195
196 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
197 SCIP_CALL( SCIPsetBoolParam(origprob, setstr, DEC_ENABLED) );
198
199 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
200 SCIP_CALL( SCIPsetBoolParam(origprob, setstr, DEC_ENABLEDFINISHING ) );
201
202 return SCIP_OKAY;
203}
204
205static
206GCG_DECL_SETPARAMFAST(setParamFastCompgreedily)
207{
208 char setstr[SCIP_MAXSTRLEN];
209 const char* name = GCGdetectorGetName(detector);
210 SCIP* origprob = GCGgetOrigprob(gcg);
211
212 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
213 SCIP_CALL( SCIPsetBoolParam(origprob, setstr, FALSE) );
214
215 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
216 SCIP_CALL( SCIPsetBoolParam(origprob, setstr, FALSE ) );
217
218 return SCIP_OKAY;
219
220}
221
222
223/*
224 * detector specific interface methods
225 */
226
227/** creates the handler for compgreedily detector and includes it in SCIP */
229 GCG* gcg /**< GCG data structure */
230 )
231{
232 GCG_DETECTORDATA* detectordata;
233
234 /**@todo create compgreedily detector data here*/
235 detectordata = NULL;
236
238
239 /**@todo add compgreedily detector parameters */
240
241 return SCIP_OKAY;
242}
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
class to manage partial decompositions
GCG_EXPORT void completeGreedily()
assigns all open constraints and open variables
GCG_EXPORT void addClockTime(SCIP_Real clocktime)
adds detection time of one detector
const char * GCGdetectorGetName(GCG_DETECTOR *detector)
returns the name of the provided detector
SCIP_RETCODE GCGincludeDetector(GCG *gcg, const char *name, const char decchar, const char *description, int freqCallRound, int maxCallRound, int minCallRound, int freqCallRoundOriginal, int maxCallRoundOriginal, int minCallRoundOriginal, int priority, SCIP_Bool enabled, SCIP_Bool enabledFinishing, SCIP_Bool enabledPostprocessing, SCIP_Bool skip, SCIP_Bool usefulRecall, GCG_DETECTORDATA *detectordata, GCG_DECL_FREEDETECTOR((*freeDetector)), GCG_DECL_INITDETECTOR((*initDetector)), GCG_DECL_EXITDETECTOR((*exitDetector)), GCG_DECL_PROPAGATEPARTIALDEC((*propagatePartialdecDetector)), GCG_DECL_FINISHPARTIALDEC((*finishPartialdecDetector)), GCG_DECL_POSTPROCESSPARTIALDEC((*postprocessPartialdecDetector)), GCG_DECL_SETPARAMAGGRESSIVE((*setParamAggressiveDetector)), GCG_DECL_SETPARAMDEFAULT((*setParamDefaultDetector)),)
constraint handler for structure detection
#define freeCompgreedily
static GCG_DECL_SETPARAMAGGRESSIVE(setParamAggressiveCompgreedily)
#define DEC_MAXCALLROUND
#define DEC_MINCALLROUNDORIGINAL
static GCG_DECL_SETPARAMDEFAULT(setParamDefaultCompgreedily)
static GCG_DECL_SETPARAMFAST(setParamFastCompgreedily)
#define DEC_ENABLEDFINISHING
#define DEC_ENABLED
#define initCompgreedily
static GCG_DECL_FINISHPARTIALDEC(finishPartialdecCompgreedily)
#define DEC_DECCHAR
#define DEC_NAME
#define DEC_MINCALLROUND
#define DEC_ENABLEDPOSTPROCESSING
#define exitCompgreedily
#define DEC_DESC
#define DEC_FREQCALLROUND
#define DEC_PRIORITY
#define DEC_USEFULRECALL
#define DEC_SKIP
#define DEC_MAXCALLROUNDORIGINAL
#define DEC_FREQCALLROUNDORIGINAL
#define detectorPostprocessPartialdecCompgreedily
SCIP_RETCODE GCGincludeDetectorCompgreedily(GCG *gcg)
static GCG_DECL_PROPAGATEPARTIALDEC(propagatePartialdecCompgreedily)
compgreedily detector
#define SCIP_MAXSTRLEN
#define SCIP_CALL_ABORT(x)
#define SCIP_CALL(x)
#define FALSE
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
#define SCIPallocMemoryArray(scip, ptr, num)
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,...)
#define NULL
Definition: struct_gcg.h:55
SCIP_DIDNOTFIND
SCIP_SUCCESS
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE