Scippy

GCG

Branch-and-Price & Column Generation for Everyone

dec_mastersetpack.cpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program */
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-2021 Operations Research, RWTH Aachen University */
10 /* Zuse Institute Berlin (ZIB) */
11 /* */
12 /* This program is free software; you can redistribute it and/or */
13 /* modify it under the terms of the GNU Lesser General Public License */
14 /* as published by the Free Software Foundation; either version 3 */
15 /* of the License, or (at your option) any later version. */
16 /* */
17 /* This program is distributed in the hope that it will be useful, */
18 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
19 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
20 /* GNU Lesser General Public License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with this program; if not, write to the Free Software */
24 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
25 /* */
26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27 
28 /**@file dec_mastersetpack.cpp
29  * @ingroup DETECTORS
30  * @brief detector mastersetpack (sets setpacking constraints to master)
31  * @author Martin Bergner
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "dec_mastersetpack.h"
37 #include "cons_decomp.h"
38 #include "class_partialdecomp.h"
39 #include "class_detprobdata.h"
40 #include "gcg.h"
41 #include "scip/cons_setppc.h"
42 #include "scip/scip.h"
43 #include "scip_misc.h"
44 #include "scip/clock.h"
45 
46 #include <iostream>
47 
48 /* constraint handler properties */
49 #define DEC_DETECTORNAME "mastersetpack" /**< name of detector */
50 #define DEC_DESC "detector mastersetpack" /**< description of detector*/
51 #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 */
52 #define DEC_MAXCALLROUND INT_MAX /**< last round the detector gets called */
53 #define DEC_MINCALLROUND 0 /**< first round the detector gets called */
54 #define DEC_FREQCALLROUNDORIGINAL 1 /**< frequency the detector gets called in detection loop while detecting the original problem */
55 #define DEC_MAXCALLROUNDORIGINAL INT_MAX /**< last round the detector gets called while detecting the original problem */
56 #define DEC_MINCALLROUNDORIGINAL 0 /**< first round the detector gets called while detecting the original problem */
57 #define DEC_PRIORITY 0 /**< priority of the constraint handler for separation */
58 #define DEC_DECCHAR '?' /**< display character of detector */
59 #define DEC_ENABLED TRUE /**< should the detection be enabled */
60 #define DEC_ENABLEDFINISHING FALSE /**< should the finishing be enabled */
61 #define DEC_ENABLEDPOSTPROCESSING FALSE /**< should the postprocessing be enabled */
62 #define DEC_SKIP FALSE /**< should detector be skipped if other detectors found decompositions */
63 #define DEC_USEFULRECALL FALSE /**< is it useful to call this detector on a descendant of the propagated partialdec */
64 /*
65  * Data structures
66  */
67 
68 /** @todo fill in the necessary detector data */
69 
70 /** detector handler data */
71 struct DEC_DetectorData
72 {
73 };
74 
75 /*
76  * Local methods
77  */
78 
79 /* put your local methods here, and declare them static */
80 
81 /*
82  * detector callback methods
83  */
84 
85 /** destructor of detector to free user data (called when GCG is exiting) */
86 #define freeMastersetpack NULL
87 
88 /** destructor of detector to free detector data (called before the solving process begins) */
89 #define exitMastersetpack NULL
90 
91 /** detection initialization function of detector (called before solving is about to begin) */
92 #define initMastersetpack NULL
93 
94 
95 static DEC_DECL_PROPAGATEPARTIALDEC(propagatePartialdecMastersetpack)
96 {
97  *result = SCIP_DIDNOTFIND;
98 
99  SCIP_CLOCK* temporaryClock;
100  SCIP_CALL_ABORT(SCIPcreateClock(scip, &temporaryClock) );
101  SCIP_CALL_ABORT( SCIPstartClock(scip, temporaryClock) );
102 
103  SCIP_CONS* cons;
104 
105  gcg::PARTIALDECOMP* partialdec = partialdecdetectiondata->workonpartialdec;
106 
107  /* set open setpacking constraints to Master */
108  auto& openconss = partialdec->getOpenconssVec();
109  for( auto itr = openconss.cbegin(); itr != openconss.cend(); )
110  {
111  cons = partialdecdetectiondata->detprobdata->getCons(*itr);
112  if( GCGconsGetType(scip, cons) == setpacking )
113  {
114  itr = partialdec->fixConsToMaster(itr);
115  }
116  else
117  {
118  ++itr;
119  }
120  }
121 
122  partialdec->sort();
123  SCIP_CALL_ABORT( SCIPstopClock(scip, temporaryClock) );
124 
125  partialdecdetectiondata->detectiontime = SCIPgetClockTime(scip, temporaryClock);
126  SCIP_CALL( SCIPallocMemoryArray(scip, &(partialdecdetectiondata->newpartialdecs), 1) );
127  partialdecdetectiondata->newpartialdecs[0] = partialdec;
128  partialdecdetectiondata->nnewpartialdecs = 1;
129  partialdecdetectiondata->newpartialdecs[0]->addClockTime(SCIPgetClockTime(scip, temporaryClock));
130  partialdecdetectiondata->newpartialdecs[0]->addDetectorChainInfo(DEC_DETECTORNAME);
131  // we used the provided partialdec -> prevent deletion
132  partialdecdetectiondata->workonpartialdec = NULL;
133  SCIP_CALL_ABORT(SCIPfreeClock(scip, &temporaryClock) );
134 
135  *result = SCIP_SUCCESS;
136 
137  return SCIP_OKAY;
138 }
139 
140 #define finishPartialdecMastersetpack NULL
141 
142 #define detectorPostprocessPartialdecMastersetpack NULL
143 #define setParamAggressiveMastersetpack NULL
144 #define setParamDefaultMastersetpack NULL
145 #define setParamFastMastersetpack NULL
146 
147 
148 /*
149  * detector specific interface methods
150  */
151 
152 /** creates the handler for mastersetpack detector and includes it in SCIP */
153 SCIP_RETCODE SCIPincludeDetectorMastersetpack(SCIP* scip /**< SCIP data structure */
154 )
155 {
156  DEC_DETECTORDATA* detectordata;
157 
158  /**@todo create mastersetpack detector data here*/
159  detectordata = NULL;
160 
161  SCIP_CALL(
163 
164  /**@todo add mastersetpack detector parameters */
165 
166  return SCIP_OKAY;
167 }
168 
169 
170 
171 
void addClockTime(SCIP_Real clocktime)
adds detection time of one detector
GCG interface methods.
#define detectorPostprocessPartialdecMastersetpack
std::vector< int >::const_iterator fixConsToMaster(std::vector< int >::const_iterator itr)
fixes a constraint to the master constraints
#define exitMastersetpack
#define DEC_MAXCALLROUND
std::vector< int > & getOpenconssVec()
Gets a vector containing constraint ids not assigned yet as vector.
#define finishPartialdecMastersetpack
#define setParamDefaultMastersetpack
constraint handler for structure detection
static DEC_DECL_PROPAGATEPARTIALDEC(propagatePartialdecMastersetpack)
#define freeMastersetpack
various SCIP helper methods
#define setParamAggressiveMastersetpack
#define DEC_DETECTORNAME
bool sort()
sorts the vars and conss data structures by their indices
SCIP_RETCODE SCIPincludeDetectorMastersetpack(SCIP *scip)
mastersetpack detector
@ setpacking
Definition: scip_misc.h:48
#define DEC_MINCALLROUND
consType GCGconsGetType(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:51
#define DEC_ENABLEDFINISHING
#define DEC_DESC
class to manage partial decompositions
SCIP_RETCODE DECincludeDetector(SCIP *scip, 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, DEC_DETECTORDATA *detectordata, DEC_DECL_FREEDETECTOR((*freeDetector)), DEC_DECL_INITDETECTOR((*initDetector)), DEC_DECL_EXITDETECTOR((*exitDetector)), DEC_DECL_PROPAGATEPARTIALDEC((*propagatePartialdecDetector)), DEC_DECL_FINISHPARTIALDEC((*finishPartialdecDetector)), DEC_DECL_POSTPROCESSPARTIALDEC((*postprocessPartialdecDetector)), DEC_DECL_SETPARAMAGGRESSIVE((*setParamAggressiveDetector)), DEC_DECL_SETPARAMDEFAULT((*setParamDefaultDetector)),)
#define DEC_ENABLED
#define DEC_FREQCALLROUND
#define DEC_MAXCALLROUNDORIGINAL
#define DEC_MINCALLROUNDORIGINAL
#define DEC_PRIORITY
class storing (potentially incomplete) decompositions
#define initMastersetpack
#define DEC_FREQCALLROUNDORIGINAL
#define DEC_SKIP
#define DEC_DECCHAR
class storing partialdecs and the problem matrix
#define setParamFastMastersetpack
#define DEC_ENABLEDPOSTPROCESSING
#define DEC_USEFULRECALL