GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
dec_generalmastersetpack.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_generalmastersetpack.cpp
30 *
31 * @brief detector for set packing constraints
32 * @author Martin Bergner
33 *
34 * This detector sets the following constraints to master:
35 * - set packing constraints
36 * - constraints with -infinity lhs and nonnegative rhs
37 *
38 */
39
40/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
41
43#include "gcg/cons_decomp.h"
46#include "gcg/gcg.h"
47#include "scip/cons_setppc.h"
48#include "scip/scip.h"
49#include "gcg/scip_misc.h"
50#include "scip/clock.h"
51
52#include <iostream>
53
54/* constraint handler properties */
55#define DEC_NAME "generalmastersetpack" /**< name of detector */
56#define DEC_DESC "detector generalmastersetpack" /**< description of detector*/
57#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 */
58#define DEC_MAXCALLROUND 0 /** last round the detector gets called */
59#define DEC_MINCALLROUND 0 /** first round the detector gets called */
60#define DEC_FREQCALLROUNDORIGINAL 1 /** frequency the detector gets called in detection loop while detecting the original problem */
61#define DEC_MAXCALLROUNDORIGINAL 0 /** last round the detector gets called while detecting the original problem */
62#define DEC_MINCALLROUNDORIGINAL 0 /** first round the detector gets called while detecting the original problem */
63#define DEC_PRIORITY 0 /**< priority of the constraint handler for separation */
64#define DEC_DECCHAR '?' /**< display character of detector */
65#define DEC_ENABLED TRUE /**< should the detection be enabled */
66#define DEC_ENABLEDFINISHING FALSE /**< should the finishing be enabled */
67#define DEC_ENABLEDPOSTPROCESSING FALSE /**< should the postprocessing be enabled */
68#define DEC_SKIP FALSE /**< should detector be skipped if other detectors found decompositions */
69#define DEC_USEFULRECALL FALSE /**< is it useful to call this detector on a descendant of the propagated partialdec */
70
71/*
72 * Data structures
73 */
74
75/** @todo fill in the necessary detector data */
76
77/** detector handler data */
79{
80};
81
82/*
83 * Local methods
84 */
85
86/* put your local methods here, and declare them static */
87
88/*
89 * detector callback methods
90 */
91
92/** destructor of detector to free user data (called when GCG is exiting) */
93#define freeGeneralmastersetpack NULL
94
95/** destructor of detector to free detector data (called before the solving process begins) */
96#define exitGeneralmastersetpack NULL
97
98/** detection initialization function of detector (called before solving is about to begin) */
99#define initGeneralmastersetpack NULL
100
101
102static GCG_DECL_PROPAGATEPARTIALDEC(propagatePartialdecGeneralmastersetpack)
103{
105 char decinfo[SCIP_MAXSTRLEN];
107
108 SCIP_CLOCK* temporaryClock;
109 SCIP_CALL_ABORT( SCIPcreateClock(origprob, &temporaryClock) );
110 SCIP_CALL_ABORT( SCIPstartClock(origprob, temporaryClock) );
111
112 SCIP_CONS* cons;
113 SCIP_VAR** vars;
114 SCIP_Real* vals;
115 int nvars;
116 bool relevant = true;
117
118
119 gcg::PARTIALDECOMP* partialdec = partialdecdetectiondata->workonpartialdec;
120 auto& openconss = partialdec->getOpenconss();
121 for( auto itr = openconss.cbegin(); itr!= openconss.cend(); )
122 {
123 bool found = false;
124 cons = partialdecdetectiondata->detprobdata->getCons(*itr);
125 /* set open setpacking constraints to master */
126 if( GCGconsGetType(origprob, cons) == setpacking )
127 {
128 itr = partialdec->fixConsToMaster(itr);
129 found = true;
130 }
131 /* set constraints with -infinity lhs and nonnegative rhs to master */
133 {
134 relevant = true;
136 vars = NULL;
137 vals = NULL;
139 relevant = false;
141 relevant = false;
142 if( nvars > 0 )
143 {
147 SCIP_CALL( GCGconsGetVals(origprob, cons, vals, nvars) );
148 }
149 for( int j = 0; j < nvars && relevant; ++j )
150 {
151 assert(vars != NULL);
152 assert(vals != NULL);
153
155 {
156 SCIPdebugPrintf("(%s is not integral) ", SCIPvarGetName(vars[j]) );
157 relevant = false;
158 }
159 if( !SCIPisEQ(origprob, vals[j], 1.0) )
160 {
161 SCIPdebugPrintf("(coeff for var %s is %.2f != 1.0) ", SCIPvarGetName(vars[j]), vals[j] );
162 relevant = false;
163 }
164 }
167
168 if(relevant)
169 {
170 itr = partialdec->fixConsToMaster(itr);
171 found = true;
172 }
173 }
174 if( !found )
175 {
176 ++itr;
177 }
178 }
179
180 partialdec->sort();
181 SCIP_CALL_ABORT( SCIPstopClock(origprob, temporaryClock) );
182
183 partialdecdetectiondata->detectiontime = SCIPgetClockTime(origprob, temporaryClock);
184 SCIP_CALL( SCIPallocMemoryArray(origprob, &(partialdecdetectiondata->newpartialdecs), 1) );
185 partialdecdetectiondata->newpartialdecs[0] = partialdec;
186 partialdecdetectiondata->nnewpartialdecs = 1;
187 (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, "genmastersetpack");
188 partialdecdetectiondata->newpartialdecs[0]->addDetectorChainInfo(decinfo);
189 partialdecdetectiondata->newpartialdecs[0]->addClockTime(SCIPgetClockTime(origprob, temporaryClock));
190 // we used the provided partialdec -> prevent deletion
191 partialdecdetectiondata->workonpartialdec = NULL;
192 SCIP_CALL_ABORT(SCIPfreeClock(origprob, &temporaryClock) );
193
195
196 return SCIP_OKAY;
197}
198
199#define finishPartialdecGeneralmastersetpack NULL
200#define detectorPostprocessPartialdecGeneralmastersetpack NULL
201
202static
203GCG_DECL_SETPARAMAGGRESSIVE(setParamAggressiveGeneralmastersetpack)
204{
205 char setstr[SCIP_MAXSTRLEN];
206 const char* name = GCGdetectorGetName(detector);
207 int newval;
209
210 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
212
213 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
215
216 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxcallround", name);
217 SCIP_CALL( SCIPgetIntParam(origprob, setstr, &newval) );
218 ++newval;
219 SCIP_CALL( SCIPsetIntParam(origprob, setstr, newval ) );
220 SCIPinfoMessage(origprob, NULL, "%s = %d\n", setstr, newval);
221
222 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origmaxcallround", name);
223 SCIP_CALL( SCIPgetIntParam(origprob, setstr, &newval) );
224 ++newval;
225 SCIP_CALL( SCIPsetIntParam(origprob, setstr, newval ) );
226 SCIPinfoMessage(origprob, NULL, "%s = %d\n", setstr, newval);
227
228 return SCIP_OKAY;
229
230}
231
232
233static
234GCG_DECL_SETPARAMDEFAULT(setParamDefaultGeneralmastersetpack)
235{
236 char setstr[SCIP_MAXSTRLEN];
237 const char* name = GCGdetectorGetName(detector);
239
240 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
242
243 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
245
246 return SCIP_OKAY;
247
248}
249
250static
251GCG_DECL_SETPARAMFAST(setParamFastGeneralmastersetpack)
252{
253 char setstr[SCIP_MAXSTRLEN];
254 const char* name = GCGdetectorGetName(detector);
256
257 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
259
260 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
262
263
264 return SCIP_OKAY;
265
266}
267
268
269/*
270 * detector specific interface methods
271 */
272
273/** creates the handler for generalmastersetpack detector and includes it in SCIP */
275 GCG* gcg /**< GCG data structure */
276 )
277{
278 GCG_DETECTORDATA* detectordata;
279
280 /**@todo create generalmastersetpack detector data here*/
281 detectordata = NULL;
282
283 SCIP_CALL(
285
286 /**@todo add generalmastersetpack detector parameters */
287
288 return SCIP_OKAY;
289}
290
291
292
293
294
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
class to manage partial decompositions
GCG_EXPORT std::vector< int > & getOpenconss()
Gets vector containing constraints not assigned yet.
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
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)),)
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 detectorPostprocessPartialdecGeneralmastersetpack
SCIP_RETCODE GCGincludeDetectorGeneralmastersetpack(GCG *gcg)
#define freeGeneralmastersetpack
#define initGeneralmastersetpack
#define exitGeneralmastersetpack
#define finishPartialdecGeneralmastersetpack
generalmastersetpack detector
#define SCIP_MAXSTRLEN
#define SCIP_Real
#define SCIP_CALL_ABORT(x)
#define TRUE
#define FALSE
GCG interface methods.
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_Real GCGconsGetRhs(SCIP *scip, SCIP_CONS *cons)
Definition scip_misc.c:109
consType GCGconsGetType(SCIP *scip, SCIP_CONS *cons)
Definition scip_misc.c:52
SCIP_RETCODE GCGconsGetVars(SCIP *scip, SCIP_CONS *cons, SCIP_VAR **vars, int nvars)
Definition scip_misc.c:487
SCIP_Real GCGconsGetLhs(SCIP *scip, SCIP_CONS *cons)
Definition scip_misc.c:207
SCIP_RETCODE GCGconsGetVals(SCIP *scip, SCIP_CONS *cons, SCIP_Real *vals, int nvals)
Definition scip_misc.c:618
int GCGconsGetNVars(SCIP *scip, SCIP_CONS *cons)
Definition scip_misc.c:433
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIP_RETCODE SCIPgetIntParam(SCIP *scip, const char *name, int *value)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
#define SCIPfreeMemoryArrayNull(scip, ptr)
#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)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
int SCIPsnprintf(char *t, int len, const char *s,...)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
* result
SCIP_VAR ** vars
int j
int nvars
#define NULL
#define SCIPdebugPrintf
various SCIP helper methods
@ setcovering
Definition scip_misc.h:50
@ setpartitioning
Definition scip_misc.h:50
@ setpacking
Definition scip_misc.h:50
@ logicor
Definition scip_misc.h:51
struct SCIP_Clock SCIP_CLOCK
struct SCIP_Cons SCIP_CONS
#define GCG_DECL_SETPARAMFAST(x)
#define GCG_DECL_SETPARAMDEFAULT(x)
#define GCG_DECL_SETPARAMAGGRESSIVE(x)
#define GCG_DECL_PROPAGATEPARTIALDEC(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
struct SCIP_Var SCIP_VAR