GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
heur_gcglinesdiving.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_gcglinesdiving.c
30 * @brief LP diving heuristic that fixes variables with a large difference to their root solution
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/heur_origdiving.h"
42#include "gcg/gcg.h"
43#include "gcg/pricer_gcg.h"
44
45
46#define HEUR_NAME "gcglinesdiving"
47#define HEUR_DESC "LP diving heuristic that chooses fixings following the line from root solution to current solution"
48#define HEUR_DISPCHAR 'l'
49#define HEUR_PRIORITY -1006000
50#define HEUR_FREQ 10
51#define HEUR_FREQOFS 6
52#define HEUR_MAXDEPTH -1
53
54
55/*
56 * Default diving rule specific parameter settings
57 */
58
59
60
61/* locally defined diving heuristic data */
62struct GCG_DivingData
63{
64 SCIP_SOL* rootsol; /**< relaxation solution at the root node */
65 SCIP_Bool firstrun; /**< is the heuristic running for the first time? */
66};
67
68
69/*
70 * Local methods
71 */
72
73/** get relaxation solution of root node (in original variables) */
74static
76 GCG* gcg, /**< GCG data structure */
77 SCIP_SOL** rootsol /**< pointer to store root relaxation solution */
78 )
79{
81 SCIP_SOL* masterrootsol;
83 int nmastervars;
84 int i;
85
86 /* get master problem */
89
90 /* allocate memory for master root LP solution */
91 SCIP_CALL( SCIPcreateSol(masterprob, &masterrootsol, NULL) );
92
93 /* get master variable information */
96 assert(nmastervars >= 0);
97
98 /* store root LP values in working master solution */
99 for( i = 0; i < nmastervars; i++ )
101
102 /* calculate original root LP solution */
104
105 /* free memory */
106 SCIP_CALL( SCIPfreeSol(masterprob, &masterrootsol) );
107
108 return SCIP_OKAY;
109}
110
111
112/*
113 * Callback methods of primal heuristic
114 */
115
116/** destructor of diving heuristic to free user data (called when GCG is exiting) */
117static
118GCG_DECL_DIVINGFREE(heurFreeGcglinesdiving) /*lint --e{715}*/
119{ /*lint --e{715}*/
121
122 assert(heur != NULL);
123
124 /* free diving rule specific data */
129
130 return SCIP_OKAY;
131}
132
133
134/** initialization method of diving heuristic (called after problem was transformed) */
135static
136GCG_DECL_DIVINGINIT(heurInitGcglinesdiving) /*lint --e{715}*/
137{ /*lint --e{715}*/
139
140 assert(heur != NULL);
141
142 /* get diving data */
145
146 /* initialize data */
147 divingdata->firstrun = TRUE;
148 divingdata->rootsol = NULL;
149
150 return SCIP_OKAY;
151}
152
153
154/** deinitialization method of diving heuristic (called before transformed problem is freed) */
155static
156GCG_DECL_DIVINGEXIT(heurExitGcglinesdiving) /*lint --e{715}*/
157{ /*lint --e{715}*/
160
161 assert(heur != NULL);
162
163 /* get diving data */
166
167 assert(divingdata->firstrun == TRUE || divingdata->rootsol != NULL);
168
169 /* free root relaxation solution */
170 if( divingdata->rootsol != NULL )
172
173 return SCIP_OKAY;
174}
175
176
177/** execution initialization method of diving heuristic (called when execution of diving heuristic is about to begin) */
178static
179GCG_DECL_DIVINGINITEXEC(heurInitexecGcglinesdiving) /*lint --e{715}*/
180{ /*lint --e{715}*/
182
183 assert(heur != NULL);
184
185 /* get diving data */
188
189 /* if the heuristic is running for the first time, the root relaxation solution needs to be stored */
190 if( divingdata->firstrun )
191 {
192 assert(divingdata->rootsol == NULL);
194 assert(divingdata->rootsol != NULL);
195 divingdata->firstrun = FALSE;
196 }
197
198 return SCIP_OKAY;
199}
200
201
202/** variable selection method of diving heuristic;
203 * finds best candidate variable w.r.t. the root LP solution:
204 * - in the projected space of fractional variables, extend the line segment connecting the root solution and
205 * the current LP solution up to the point, where one of the fractional variables becomes integral
206 * - round this variable to the integral value
207 */
208static
209GCG_DECL_DIVINGSELECTVAR(heurSelectVarGcglinesdiving) /*lint --e{715}*/
210{ /*lint --e{715}*/
216 int c;
218
219 /* check preconditions */
221 assert(heur != NULL);
222 assert(bestcand != NULL);
224 assert(bestcandroundup != NULL);
225
226 /* get diving data */
229 assert(divingdata->rootsol != NULL);
230
231 /* get fractional variables that should be integral */
235
238
239 /* get best candidate */
240 for( c = 0; c < nlpcands; ++c )
241 {
242 SCIP_VAR* var;
243 SCIP_Bool roundup;
244 SCIP_Real distquot;
246 SCIP_Real rootsolval;
247
248 int i;
249
250 var = lpcands[c];
251
252 /* if the variable is on the tabu list, do not choose it */
253 for( i = 0; i < tabulistsize; ++i )
254 if( tabulist[i] == var )
255 break;
256 if( i < tabulistsize )
257 continue;
258
260 rootsolval = SCIPgetSolVal(origprob, divingdata->rootsol, var);
261
262 /* calculate distance to integral value divided by distance to root solution */
263 if( SCIPisLT(origprob, solval, rootsolval) )
264 {
265 roundup = FALSE;
266 distquot = (solval - SCIPfeasFloor(origprob, solval)) / (rootsolval - solval);
267
268 /* avoid roundable candidates */
270 distquot *= 1000.0;
271 }
272 else if( SCIPisGT(origprob, solval, rootsolval) )
273 {
274 roundup = TRUE;
275 distquot = (SCIPfeasCeil(origprob, solval) - solval) / (solval - rootsolval);
276
277 /* avoid roundable candidates */
279 distquot *= 1000.0;
280 }
281 else
282 {
283 roundup = FALSE;
284 distquot = SCIPinfinity(origprob);
285 }
286
287 /* check, if candidate is new best candidate */
288 if( distquot < bestdistquot )
289 {
290 *bestcand = var;
292 *bestcandroundup = roundup;
293 bestdistquot = distquot;
294 }
295 }
296
297 return SCIP_OKAY;
298}
299
300
301/*
302 * primal heuristic specific interface methods
303 */
304
305/** creates the gcglinesdiving heuristic and includes it in GCG */
307 GCG* gcg /**< GCG data structure */
308 )
309{
310 SCIP_HEUR* heur;
312
313 /* create gcglinesdiving primal heuristic data */
315
316 /* include diving heuristic */
319 HEUR_MAXDEPTH, heurFreeGcglinesdiving, heurInitGcglinesdiving, heurExitGcglinesdiving, NULL, NULL,
320 heurInitexecGcglinesdiving, NULL, heurSelectVarGcglinesdiving, divingdata) );
321
322 assert(heur != NULL);
323
324 return SCIP_OKAY;
325}
#define SCIP_Bool
#define SCIP_Real
#define TRUE
#define FALSE
GCG interface methods.
SCIP_RETCODE GCGtransformMastersolToOrigsol(GCG *gcg, SCIP_SOL *mastersol, SCIP_SOL **origsol, SCIP_Bool ignorelocalvarbnds, SCIP_Bool *violatesvarbnds)
Definition misc.c:135
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
SCIP_RETCODE SCIPgetExternBranchCands(SCIP *scip, SCIP_VAR ***externcands, SCIP_Real **externcandssol, SCIP_Real **externcandsscore, int *nexterncands, int *nprioexterncands, int *nprioexternbins, int *nprioexternints, int *nprioexternimpls)
#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 SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPvarMayRoundUp(SCIP_VAR *var)
SCIP_Bool SCIPvarMayRoundDown(SCIP_VAR *var)
SCIP_Real SCIPvarGetRootSol(SCIP_VAR *var)
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
* bestcandmayround
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
#define HEUR_FREQOFS
#define HEUR_DESC
GCGheurSetDivingDataOrig(heur, NULL)
#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
static SCIP_RETCODE getRootRelaxSol(GCG *gcg, SCIP_SOL **rootsol)
SCIP_VAR * var
SCIP_Real solval
int i
SCIP_RETCODE GCGincludeHeurGcglinesdiving(GCG *gcg)
divingdata rootsol
SCIP_Real bestdistquot
LP diving heuristic that fixes variables with a large difference to their root solution.
SCIP_VAR ** mastervars
int nmastervars
SCIP_VAR ** tabulist
SCIP_RETCODE GCGincludeDivingHeurOrig(GCG *gcg, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, GCG_DECL_DIVINGFREE((*divingfree)), GCG_DECL_DIVINGINIT((*divinginit)), GCG_DECL_DIVINGEXIT((*divingexit)), GCG_DECL_DIVINGINITSOL((*divinginitsol)), GCG_DECL_DIVINGEXITSOL((*divingexitsol)), GCG_DECL_DIVINGINITEXEC((*divinginitexec)), GCG_DECL_DIVINGEXITEXEC((*divingexitexec)), GCG_DECL_DIVINGSELECTVAR((*divingselectvar)), GCG_DIVINGDATA *divingdata)
GCG_DIVINGDATA * GCGheurGetDivingDataOrig(SCIP_HEUR *heur)
primal heuristic interface for LP diving heuristics on the original variables
#define NULL
GCG variable pricer.
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_Heur SCIP_HEUR
#define GCG_DECL_DIVINGFREE(x)
#define GCG_DECL_DIVINGEXIT(x)
#define GCG_DECL_DIVINGINITEXEC(x)
#define GCG_DECL_DIVINGINIT(x)
#define GCG_DECL_DIVINGSELECTVAR(x)
struct GCG_DivingData GCG_DIVINGDATA
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR