Scippy

GCG

Branch-and-Price & Column Generation for Everyone

heur_masterlinesdiving.c
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 heur_masterlinesdiving.c
29  * @brief LP diving heuristic that fixes variables with a large difference to their root solution
30  * @author Tobias Achterberg
31  * @author Christian Puchert
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include <assert.h>
37 #include <string.h>
38 
39 #include "heur_masterlinesdiving.h"
40 #include "heur_masterdiving.h"
41 
42 
43 #define HEUR_NAME "masterlinesdiving"
44 #define HEUR_DESC "master LP diving heuristic that chooses fixings following the line from root solution to current solution"
45 #define HEUR_DISPCHAR 'l'
46 #define HEUR_PRIORITY -1006000
47 #define HEUR_FREQ 10
48 #define HEUR_FREQOFS 6
49 #define HEUR_MAXDEPTH -1
50 
51 
52 /*
53  * Callback methods
54  */
55 
56 /** variable selection method of diving heuristic;
57  * finds best candidate variable w.r.t. the root LP solution:
58  * - in the projected space of fractional variables, extend the line segment connecting the root solution and
59  * the current LP solution up to the point, where one of the fractional variables becomes integral
60  * - round this variable to the integral value
61  */
62 static
63 GCG_DECL_DIVINGSELECTVAR(heurSelectVarMasterlinesdiving) /*lint --e{715}*/
64 { /*lint --e{715}*/
65  SCIP_VAR** lpcands;
66  SCIP_Real* lpcandssol;
67  SCIP_Real* lpcandsfrac;
68  int nlpcands;
69  SCIP_Real bestdistquot;
70  int c;
71 
72  /* check preconditions */
73  assert(scip != NULL);
74  assert(heur != NULL);
75  assert(bestcand != NULL);
76  assert(bestcandmayround != NULL);
77 
78  /* get fractional variables that should be integral */
79  SCIP_CALL( SCIPgetLPBranchCands(scip, &lpcands, &lpcandssol, &lpcandsfrac, &nlpcands, NULL, NULL) );
80  assert(lpcands != NULL);
81  assert(lpcandsfrac != NULL);
82  assert(lpcandssol != NULL);
83 
84  *bestcandmayround = TRUE;
85  bestdistquot = SCIPinfinity(scip);
86 
87  /* get best candidate */
88  for( c = 0; c < nlpcands; ++c )
89  {
90  SCIP_VAR* var;
91  SCIP_Real solval;
92  SCIP_Real rootsolval;
93  SCIP_Real distquot;
94 
95  int i;
96 
97  var = lpcands[c];
98  solval = lpcandssol[c];
99  rootsolval = SCIPvarGetRootSol(var);
100 
101  /* if the variable is on the tabu list, do not choose it */
102  for( i = 0; i < tabulistsize; ++i )
103  if( tabulist[i] == var )
104  break;
105  if( i < tabulistsize )
106  continue;
107 
108  if( SCIPisGT(scip, solval, rootsolval) )
109  {
110  distquot = (SCIPfeasCeil(scip, solval) - solval) / (solval - rootsolval);
111 
112  /* avoid roundable candidates */
113  if( SCIPvarMayRoundUp(var) )
114  distquot *= 1000.0;
115  }
116  else
117  distquot = SCIPinfinity(scip);
118 
119  /* check whether the variable is roundable */
120  *bestcandmayround = *bestcandmayround && (SCIPvarMayRoundDown(var) || SCIPvarMayRoundUp(var));
121 
122  /* check, if candidate is new best candidate */
123  if( distquot < bestdistquot )
124  {
125  *bestcand = var;
126  bestdistquot = distquot;
127  }
128  }
129 
130  return SCIP_OKAY;
131 }
132 
133 
134 /*
135  * heuristic specific interface methods
136  */
137 
138 /** creates the masterlinesdiving heuristic and includes it in GCG */
140  SCIP* scip /**< SCIP data structure */
141  )
142 {
143  SCIP_HEUR* heur;
144 
145  /* include diving heuristic */
146  SCIP_CALL( GCGincludeDivingHeurMaster(scip, &heur,
148  HEUR_MAXDEPTH, NULL, NULL, NULL, NULL, NULL, NULL, NULL, heurSelectVarMasterlinesdiving, NULL) );
149 
150  assert(heur != NULL);
151 
152  return SCIP_OKAY;
153 }
static GCG_DECL_DIVINGSELECTVAR(heurSelectVarMasterlinesdiving)
SCIP_RETCODE GCGincludeHeurMasterlinesdiving(SCIP *scip)
#define HEUR_NAME
#define HEUR_FREQOFS
#define HEUR_FREQ
#define HEUR_MAXDEPTH
primal heuristic interface for LP diving heuristics on the master variables
#define HEUR_DESC
master LP diving heuristic that fixes variables with a large difference to their root solution
#define HEUR_DISPCHAR
#define HEUR_PRIORITY
SCIP_RETCODE GCGincludeDivingHeurMaster(SCIP *scip, 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)