GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
heur_gcgsimplerounding.c
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 heur_gcgsimplerounding.c
30 * @brief simple and fast LP rounding heuristic
31 * @author Tobias Achterberg
32 * @author Christian Puchert
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37#include <assert.h>
38#include <string.h>
39
41#include "gcg/gcg.h"
42
43
44#define HEUR_NAME "gcgsimplerounding"
45#define HEUR_DESC "simple and fast LP rounding heuristic on original variables"
46#define HEUR_DISPCHAR 'r'
47#define HEUR_PRIORITY 0
48#define HEUR_FREQ 1
49#define HEUR_FREQOFS 0
50#define HEUR_MAXDEPTH -1
51#define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
52#define HEUR_USESSUBSCIP FALSE
53
54
55/* locally defined heuristic data */
56struct SCIP_HeurData
57{
58 GCG* gcg; /**< GCG data structure */
59 SCIP_SOL* sol; /**< working solution */
60 SCIP_Longint lastlp; /**< last LP number where the heuristic was applied */
61 int nroundablevars; /**< number of variables that can be rounded (-1 if not yet calculated) */
62};
63
64
65
66
67/*
68 * Callback methods
69 */
70
71/** copy method for primal heuristic plugins (called when SCIP copies plugins) */
72#define heurCopyGcgsimplerounding NULL
73
74/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
75static
76SCIP_DECL_HEURFREE(heurFreeGcgsimplerounding) /*lint --e{715}*/
77{ /*lint --e{715}*/
79
80 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
81
84
86
87 return SCIP_OKAY;
88}
89
90
91/** initialization method of primal heuristic (called after problem was transformed) */
92static
93SCIP_DECL_HEURINIT(heurInitGcgsimplerounding) /*lint --e{715}*/
94{ /*lint --e{715}*/
96
97 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
98
100 assert(heurdata != NULL);
101
102 /* create heuristic data */
106
107 return SCIP_OKAY;
108}
109
110
111/** deinitialization method of primal heuristic (called before transformed problem is freed) */
112static
113SCIP_DECL_HEUREXIT(heurExitGcgsimplerounding) /*lint --e{715}*/
114{ /*lint --e{715}*/
116
117 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
118
119 /* free heuristic data */
121 assert(heurdata != NULL);
123
124 return SCIP_OKAY;
125}
126
127
128/** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
129static
130SCIP_DECL_HEURINITSOL(heurInitsolGcgsimplerounding)
131{
133
134 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
135
137 assert(heurdata != NULL);
138 heurdata->lastlp = -1;
139
140 return SCIP_OKAY;
141}
142
143
144/** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
145#define heurExitsolGcgsimplerounding NULL
146
147
148/** execution method of primal heuristic */
149static
150SCIP_DECL_HEUREXEC(heurExecGcgsimplerounding) /*lint --e{715}*/
151{ /*lint --e{715}*/
159 int c;
160
161 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
163
164 /* get heuristic data */
166 assert(heurdata != NULL);
167
168 /* get master problem */
171
173
174 /* do not execute the heuristic on invalid relaxation solutions
175 * (which is the case if the node has been cut off)
176 */
178 {
179 SCIPdebugMessage("skipping GCG simple rounding: invalid relaxation solution\n");
180 return SCIP_OKAY;
181 }
182
183 /* only call heuristic, if an optimal LP solution is at hand */
185 return SCIP_OKAY;
186
187 /* on our first call, calculate the number of roundable variables */
188 if( heurdata->nroundablevars == -1 )
189 {
190 SCIP_VAR** vars;
191 int nvars;
192 int nroundablevars;
193 int i;
194
197 nroundablevars = 0;
198 for( i = 0; i < nvars; ++i )
199 {
202 }
204 }
205
206 /* don't call heuristic if there are no roundable variables */
207 if( heurdata->nroundablevars == 0 )
208 return SCIP_OKAY;
209
210 /* don't call heuristic, if we have already processed the current LP solution */
213 return SCIP_OKAY;
215
216 /* get fractional variables, that should be integral */
218
219 /* only call heuristic, if LP solution is fractional */
220 if( nlpcands == 0 )
221 return SCIP_OKAY;
222
223 /* don't call heuristic, if there are more fractional variables than roundable ones */
225 return SCIP_OKAY;
226
228
229 SCIPdebugMessage("executing GCG simple rounding heuristic: %d fractionals\n", nlpcands);
230
231 /* get the working solution from heuristic's local data */
232 sol = heurdata->sol;
233 assert(sol != NULL);
234
235 /* copy the current LP solution to the working solution */
237
238 /* round all roundable fractional columns in the corresponding direction as long as no unroundable column was found */
239 for( c = 0; c < nlpcands; ++c )
240 {
241 SCIP_VAR* var;
243 SCIP_Real newsolval;
244 SCIP_Bool mayrounddown;
245 SCIP_Bool mayroundup;
246
249 var = lpcands[c];
251 mayrounddown = SCIPvarMayRoundDown(var);
252 mayroundup = SCIPvarMayRoundUp(var);
253 SCIPdebugMessage("GCG simple rounding heuristic: var <%s>, val=%g, rounddown=%u, roundup=%u\n",
254 SCIPvarGetName(var), oldsolval, mayrounddown, mayroundup);
255
256 /* choose rounding direction */
257 if( mayrounddown && mayroundup )
258 {
259 /* we can round in both directions: round in objective function direction */
260 if( SCIPvarGetObj(var) >= 0.0 )
261 newsolval = SCIPfeasFloor(scip, oldsolval);
262 else
263 newsolval = SCIPfeasCeil(scip, oldsolval);
264 }
265 else if( mayrounddown )
266 newsolval = SCIPfeasFloor(scip, oldsolval);
267 else if( mayroundup )
268 newsolval = SCIPfeasCeil(scip, oldsolval);
269 else
270 break;
271
272 /* store new solution value */
273 SCIP_CALL( SCIPsetSolVal(scip, sol, var, newsolval) );
274 }
275
276 /* check, if rounding was successful */
277 if( c == nlpcands )
278 {
279 SCIP_Bool stored;
280
281 /* check solution for feasibility, and add it to solution store if possible
282 * neither integrality nor feasibility of LP rows has to be checked, because all fractional
283 * variables were already moved in feasible direction to the next integer
284 */
286
287 if( stored )
288 {
289#ifdef SCIP_DEBUG
290 SCIPdebugMessage("found feasible rounded solution:\n");
292#endif
294 }
295 }
296
297 return SCIP_OKAY;
298}
299
300
301
302
303/*
304 * heuristic specific interface methods
305 */
306
307/** creates the GCG simple rounding heuristic and includes it in SCIP */
309 GCG* gcg /**< GCG data structure */
310 )
311{
314
316 heurdata->gcg = gcg;
317
318 /* include heuristic */
321 heurCopyGcgsimplerounding, heurFreeGcgsimplerounding, heurInitGcgsimplerounding, heurExitGcgsimplerounding,
322 heurInitsolGcgsimplerounding, heurExitsolGcgsimplerounding, heurExecGcgsimplerounding, heurdata) );
323
324 return SCIP_OKAY;
325}
326
SCIP_DECL_HEUREXIT(Heur2opt::scip_exit)
SCIP_DECL_HEURINIT(Heur2opt::scip_init)
SCIP_DECL_HEURINITSOL(Heur2opt::scip_initsol)
SCIP_DECL_HEURFREE(Heur2opt::scip_free)
SCIP_DECL_HEUREXEC(Heur2opt::scip_exec)
#define SCIP_Longint
#define SCIP_Bool
#define SCIP_Real
#define FALSE
GCG interface methods.
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
SCIP_STAGE SCIPgetStage(SCIP *scip)
int SCIPgetNIntVars(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
int SCIPgetNBinVars(SCIP *scip)
SCIP_RETCODE SCIPgetExternBranchCands(SCIP *scip, SCIP_VAR ***externcands, SCIP_Real **externcandssol, SCIP_Real **externcandsscore, int *nexterncands, int *nprioexterncands, int *nprioexternbins, int *nprioexternints, int *nprioexternimpls)
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
SCIP_RETCODE SCIPincludeHeur(SCIP *scip, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEURCOPY((*heurcopy)), SCIP_DECL_HEURFREE((*heurfree)), SCIP_DECL_HEURINIT((*heurinit)), SCIP_DECL_HEUREXIT((*heurexit)), SCIP_DECL_HEURINITSOL((*heurinitsol)), SCIP_DECL_HEUREXITSOL((*heurexitsol)), SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
const char * SCIPheurGetName(SCIP_HEUR *heur)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
#define SCIPallocMemory(scip, ptr)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
SCIP_RETCODE SCIPlinkRelaxSol(SCIP *scip, SCIP_SOL *sol)
SCIP_RETCODE SCIPtrySol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIP_Longint SCIPgetNLPs(SCIP *scip)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPvarMayRoundUp(SCIP_VAR *var)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
SCIP_Bool SCIPvarMayRoundDown(SCIP_VAR *var)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Bool SCIPisRelaxSolValid(SCIP *scip)
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
#define HEUR_FREQOFS
#define HEUR_DESC
#define HEUR_DISPCHAR
#define HEUR_MAXDEPTH
#define HEUR_PRIORITY
SCIP_Real * lpcandssol
#define HEUR_NAME
static SCIP_VAR ** lpcands
int nlpcands
SCIP * origprob
#define HEUR_FREQ
#define HEUR_TIMING
#define HEUR_USESSUBSCIP
* result
SCIP_VAR * var
SCIP_VAR ** vars
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
static SCIP_HEURDATA * heurdata
int nvars
SCIP_Real oldsolval
heurdata lastlp
SCIP_SOL * sol
SCIP_Longint nlps
#define heurCopyGcgsimplerounding
#define heurExitsolGcgsimplerounding
SCIP_RETCODE GCGincludeHeurGcgsimplerounding(GCG *gcg)
heurdata nroundablevars
simple and fast LP rounding heuristic
#define NULL
SCIP_Longint lastlp
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_HeurData SCIP_HEURDATA
SCIP_LPSOLSTAT_OPTIMAL
SCIP_DIDNOTRUN
SCIP_DIDNOTFIND
SCIP_FOUNDSOL
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_SOLVING
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR
SCIP_VARSTATUS_COLUMN