GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
dec_densemasterconss.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_densemasterconss.cpp
30 *
31 * @brief detector densemasterconss (put your description here)
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 "gcg/gcg.h"
42#include "scip/cons_setppc.h"
43#include "scip/scip.h"
44#include "gcg/scip_misc.h"
45#include "scip/clock.h"
46
47#include <sstream>
48
49#include <iostream>
50#include <algorithm>
51
52
53/* constraint handler properties */
54#define DEC_NAME "densemasterconss" /**< name of detector */
55#define DEC_DESC "detector densemasterconss" /**< description of detector*/
56#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 */
57#define DEC_MAXCALLROUND 0 /** last round the detector gets called */
58#define DEC_MINCALLROUND 0 /** first round the detector gets called */
59#define DEC_FREQCALLROUNDORIGINAL 1 /** frequency the detector gets called in detection loop while detecting the original problem */
60#define DEC_MAXCALLROUNDORIGINAL INT_MAX /** last round the detector gets called while detecting the original problem */
61#define DEC_MINCALLROUNDORIGINAL 0 /** first round the detector gets called while detecting the original problem */
62#define DEC_PRIORITY 0 /**< priority of the constraint handler for separation */
63#define DEC_DECCHAR 'd' /**< display character of detector */
64#define DEC_ENABLED TRUE /**< should the detection be enabled */
65#define DEC_ENABLEDFINISHING FALSE /**< should the detection be enabled */
66#define DEC_ENABLEDPOSTPROCESSING FALSE /**< should the postprocessing be enabled */
67#define DEC_SKIP FALSE /**< should detector be skipped if other detectors found decompositions */
68#define DEC_USEFULRECALL FALSE /**< is it useful to call this detector on a descendant of the propagated partialdec */
69
70/*
71 * Data structures
72 */
73
74/** @todo fill in the necessary detector data */
75
76/** detector handler data */
78{
79};
80
81/*
82 * Local methods
83 */
84
85struct sort_pred {
86 bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
87 return left.first > right.first;
88 }
89};
90
91/* put your local methods here, and declare them static */
92
93/*
94 * detector callback methods
95 */
96
97/** destructor of detector to free user data (called when GCG is exiting) */
98#define freeDensemasterconss NULL
99
100/** destructor of detector to free detector data (called before the solving process begins) */
101#define exitDensemasterconss NULL
102
103/** detection initialization function of detector (called before solving is about to begin) */
104#define initDensemasterconss NULL
105
106#define detectDensemasterconss NULL
107
108#define finishPartialdecDensemasterconss NULL
109
110static GCG_DECL_PROPAGATEPARTIALDEC(propagatePartialdecDensemasterconss)
111{
113 char decinfo[SCIP_MAXSTRLEN];
114
115 SCIP_CLOCK* temporaryClock;
117 gcg::DETPROBDATA* detprobdata;
118 gcg::PARTIALDECOMP* partialdec = partialdecdetectiondata->workonpartialdec;
119 std::stringstream decdesc;
120
121 SCIP_Real maxratio = 0.2;
122 int maxdiff = -1;
123 int maxdiffindex = -1;
124 int lastindex = -1;
125
126 detprobdata = partialdecdetectiondata->detprobdata;
127
128 SCIP_CALL_ABORT( SCIPcreateClock(origprob, &temporaryClock) );
129 SCIP_CALL_ABORT( SCIPstartClock(origprob, temporaryClock) );
130
131 lastindex = maxratio * detprobdata->getNConss();
132 /* fix open conss that have a) type of the current subset or b) decomp info ONLY_MASTER as master conss */
133 std::vector<std::pair<int,int>> nnonzeros(detprobdata->getNConss(), std::pair<int, int>(0, -1));
134 for( int cons: partialdec->getOpenconss() )
135 {
136 nnonzeros[cons] = std::pair<int,int>(detprobdata->getNVarsForCons(cons), cons);
137 }
138
139 std::sort(nnonzeros.begin(), nnonzeros.end(), sort_pred() );
140
141 for( int i = 0; i < lastindex && i < (int) nnonzeros.size() - 1; ++i )
142 {
143 if( maxdiff < nnonzeros[i].first - nnonzeros[i+1].first )
144 {
145 maxdiff = nnonzeros[i].first - nnonzeros[i+1].first;
146 maxdiffindex = i;
147 }
148 }
149
150 for( int i = 0; i < maxdiffindex; ++i )
151 {
152 partialdec->fixConsToMaster(nnonzeros[i].second);
153 }
154
155 decdesc << "densemasterconss" << "\\_" << maxdiffindex ;
156
157 partialdec->sort();
158 (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, decdesc.str().c_str());
159 partialdec->addDetectorChainInfo(decinfo);
160
161 SCIP_CALL_ABORT( SCIPstopClock(origprob, temporaryClock ) );
162
163 partialdecdetectiondata->detectiontime = SCIPgetClockTime(origprob, temporaryClock);
164 SCIP_CALL( SCIPallocMemoryArray(origprob, &(partialdecdetectiondata->newpartialdecs), 1) );
165 partialdecdetectiondata->nnewpartialdecs = 1;
166
167 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, "dec_densemasterconss found %d new partialdec \n", partialdecdetectiondata->nnewpartialdecs );
168
169 partialdecdetectiondata->newpartialdecs[0] = partialdec;
170 partialdecdetectiondata->newpartialdecs[0]->addClockTime(SCIPgetClockTime(origprob, temporaryClock));
171 // we used the provided partialdec -> prevent deletion
172 partialdecdetectiondata->workonpartialdec = NULL;
173
174 SCIP_CALL_ABORT(SCIPfreeClock(origprob, &temporaryClock) );
175
177
178 return SCIP_OKAY;
179}
180
181#define detectorPostprocessPartialdecDensemasterconss NULL
182
183static
184GCG_DECL_SETPARAMAGGRESSIVE(setParamAggressiveDensemasterconss)
185{
186 char setstr[SCIP_MAXSTRLEN];
187 const char* name = GCGdetectorGetName(detector);
189
190 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
192
193 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
195
196 return SCIP_OKAY;
197}
198
199
200static
201GCG_DECL_SETPARAMDEFAULT(setParamDefaultDensemasterconss)
202{
203 char setstr[SCIP_MAXSTRLEN];
204 const char* name = GCGdetectorGetName(detector);
206
207 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
209
210 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
212
213 return SCIP_OKAY;
214}
215
216static
217GCG_DECL_SETPARAMFAST(setParamFastDensemasterconss)
218{
219 char setstr[SCIP_MAXSTRLEN];
220 const char* name = GCGdetectorGetName(detector);
222
223 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
225
226 (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
228
229
230 return SCIP_OKAY;
231}
232
233
234/*
235 * detector specific interface methods
236 */
237
238/** creates the handler for densemasterconss detector and includes it in SCIP */
240 GCG* gcg /**< GCG data structure */
241 )
242{
243 GCG_DETECTORDATA* detectordata;
244
245 /**@todo create densemasterconss detector data here*/
246 detectordata = NULL;
247
248 SCIP_CALL(
251 freeDensemasterconss, initDensemasterconss, exitDensemasterconss, propagatePartialdecDensemasterconss, finishPartialdecDensemasterconss, detectorPostprocessPartialdecDensemasterconss, setParamAggressiveDensemasterconss, setParamDefaultDensemasterconss, setParamFastDensemasterconss));
252
253 /**@todo add densemasterconss detector parameters */
254
255 return SCIP_OKAY;
256}
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
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
class to manage partial decompositions
GCG_EXPORT void addDetectorChainInfo(const char *decinfo)
add information about the detector chain
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 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 initDensemasterconss
#define detectorPostprocessPartialdecDensemasterconss
#define freeDensemasterconss
#define finishPartialdecDensemasterconss
SCIP_RETCODE GCGincludeDetectorDensemasterconss(GCG *gcg)
#define exitDensemasterconss
densemasterconss 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
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
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,...)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
* result
int i
#define NULL
various SCIP helper methods
bool operator()(const std::pair< int, int > &left, const std::pair< int, int > &right)
struct SCIP_Clock SCIP_CLOCK
#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_VERBLEVEL_HIGH
SCIP_DIDNOTFIND
SCIP_SUCCESS
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP