Scippy

GCG

Branch-and-Price & Column Generation for Everyone

gcg.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 gcg.cpp
30 * @brief methods for working with gcg structure
31 * @author Erik Muehmer
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#include "scip/scip.h"
37#include "gcg/struct_gcg.h"
38#include "gcg/gcgplugins.h"
39#include "gcg/benders_gcg.h"
40#include "gcg/pricer_gcg.h"
41#include "gcg/objpricer_gcg.h"
42
43/** create a gcg struct */
44extern "C"
46 GCG** gcg /**< pointer to store GCG data structure */
47 )
48{
49 SCIP* origprob;
50 *gcg = (GCG*) malloc(sizeof(GCG));
51 SCIP_CALL( SCIPcreate(&origprob) );
52
53 (*gcg)->origprob = origprob;
54 (*gcg)->masterprob = NULL;
55 (*gcg)->bendersmasterprob = NULL;
56 (*gcg)->dwmasterprob = NULL;
57 (*gcg)->relax = NULL;
58 (*gcg)->pricer = NULL;
59 (*gcg)->sepaorig = NULL;
60
61 /* include gcg plugins */
63 return SCIP_OKAY;
64}
65
66/** free a gcg column */
67extern "C"
69 GCG** gcg /**< pointer to gcg structure */
70 )
71{
72 SCIP* origprob;
73
74 if( gcg == NULL || (*gcg) == NULL )
75 return SCIP_OKAY;
76
77 origprob = (*gcg)->origprob;
78 assert(origprob != NULL);
79 SCIP_CALL( SCIPfree(&origprob) );
80 free(*gcg);
81 return SCIP_OKAY;
82}
83
84#ifndef NDEBUG
85/** returns the original problem */
86extern "C"
88 GCG* gcg /**< GCG data structure */
89 )
90{
91 assert(gcg != NULL);
92 return gcg->origprob;
93}
94#endif
95
96#ifndef NDEBUG
97/** returns the active master problem (may change until solving is initiated) */
98extern "C"
100 GCG* gcg /**< GCG data structure */
101 )
102{
103 assert(gcg != NULL);
104 return gcg->masterprob;
105}
106#endif
107
108#ifndef NDEBUG
109/** returns the benders master problem (also used to solve the original problem directly) */
110extern "C"
112 GCG* gcg /**< GCG data structure */
113 )
114{
115 assert(gcg != NULL);
116 return gcg->bendersmasterprob;
117}
118#endif
119
120#ifndef NDEBUG
121/** returns the dw master problem */
122extern "C"
124 GCG* gcg /**< GCG data structure */
125 )
126{
127 assert(gcg != NULL);
128 return gcg->dwmasterprob;
129}
130#endif
131
132/** returns the GCG data structure */
133extern "C"
135 SCIP* masterprob /**< SCIP data structure */
136 )
137{
138 SCIP_BENDERS* benders;
139 SCIP_PRICER* pricer;
140
141 assert(masterprob != NULL);
142
143 /* retrieving the Benders' decomposition and the pricer plugins. There should only be one or the other for a given
144 * master problem. If there are both, then an error is returned */
145 benders = SCIPfindBenders(masterprob, "gcg");
146 pricer = SCIPfindPricer(masterprob, "gcg");
147 assert((benders != NULL && pricer == NULL) || (pricer != NULL && benders == NULL));
148
149 if( benders != NULL && pricer == NULL )
150 {
151 return GCGbendersGetGcg(benders);
152 }
153 else if( pricer != NULL && benders == NULL )
154 {
155 return GCGpricerGetGcg(masterprob);
156 }
157
158 SCIPerrorMessage("There must exist either a pricer or a benders or neither, not both.\n");
159
160 return NULL;
161}
162
163/** returns the GCG data structure */
164extern "C"
166 SCIP* origprob /**< SCIP data structure */
167 )
168{
169 assert(origprob != NULL);
170 return GCGrelaxGetGcg(origprob);
171}
172
173#ifndef NDEBUG
174/** gets GCG's relaxator */
175extern "C"
177 GCG* gcg /**< GCG data structure */
178 )
179{
180 assert(gcg != NULL);
181 return gcg->relax;
182}
183#endif
184
185#ifndef NDEBUG
186/** gets the GCG pricer */
188 GCG* gcg /**< GCG data structure */
189 )
190{
191 assert(gcg != NULL);
192 return reinterpret_cast<ObjPricerGcg*>(gcg->pricer);
193}
194#endif
195
196#ifndef NDEBUG
197/** gets the orig separator */
199 GCG* gcg /**< GCG data structure */
200 )
201{
202 assert(gcg != NULL);
203 return gcg->sepaorig;
204}
205#endif
206
207#ifndef NDEBUG
208/** gets the master separator cut event handler */
210 GCG* gcg /**< GCG data structure */
211 )
212{
213 assert(gcg != NULL);
214 return gcg->mastersepacuthdlr;
215}
216#endif
GCG Benders' decomposition.
#define SCIP_CALL(x)
SCIP_EVENTHDLR * GCGgetMastersepacutEventhdlr(GCG *gcg)
Definition: gcg.cpp:209
SCIP_SEPA * GCGgetSepaorig(GCG *gcg)
Definition: gcg.cpp:198
SCIP_RELAX * GCGgetRelax(GCG *gcg)
Definition: gcg.cpp:176
SCIP_RETCODE GCGincludeGcgPlugins(GCG *gcg)
Definition: gcgplugins.c:316
SCIP plugins for generic column generation.
GCG * GCGbendersGetGcg(SCIP_BENDERS *benders)
Definition: benders_gcg.c:798
GCG * GCGpricerGetGcg(SCIP *masterprob)
GCG * GCGorigGetGcg(SCIP *origprob)
Definition: gcg.cpp:165
ObjPricerGcg * GCGgetObjPricer(GCG *gcg)
Definition: gcg.cpp:187
GCG * GCGmasterGetGcg(SCIP *masterprob)
Definition: gcg.cpp:134
SCIP * GCGgetBendersMasterprob(GCG *gcg)
Definition: gcg.cpp:111
SCIP * GCGgetDwMasterprob(GCG *gcg)
Definition: gcg.cpp:123
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
SCIP * GCGgetMasterprob(GCG *gcg)
Definition: gcg.cpp:99
SCIP_RETCODE GCGcreate(GCG **gcg)
Definition: gcg.cpp:45
SCIP_RETCODE GCGfree(GCG **gcg)
Definition: gcg.cpp:68
SCIP_RETCODE SCIPfree(SCIP **scip)
SCIP_RETCODE SCIPcreate(SCIP **scip)
SCIP_BENDERS * SCIPfindBenders(SCIP *scip, const char *name)
SCIP_PRICER * SCIPfindPricer(SCIP *scip, const char *name)
#define NULL
GCG variable pricer.
GCG variable pricer.
#define SCIPerrorMessage
GCG_EXPORT GCG * GCGrelaxGetGcg(SCIP *origprob)
Definition: relax_gcg.c:5788
Definition: struct_gcg.h:55
SCIP_PROB * origprob
gcg data structure
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE