Scippy

GCG

Branch-and-Price & Column Generation for Everyone

heur_mastercoefdiving.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_mastercoefdiving.c
30 * @brief master LP diving heuristic that chooses fixings w.r.t. the matrix coefficients
31 * @author Tobias Achterberg
32 * @author Marc Pfetsch
33 * @author Christian Puchert
34 */
35
36/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
37
38#include <assert.h>
39#include <string.h>
40
43
44
45#define HEUR_NAME "mastercoefdiving"
46#define HEUR_DESC "master LP diving heuristic that chooses fixings w.r.t. the matrix coefficients"
47#define HEUR_DISPCHAR 'c'
48#define HEUR_PRIORITY -1001000
49#define HEUR_FREQ 10
50#define HEUR_FREQOFS 1
51#define HEUR_MAXDEPTH -1
52
53
54/*
55 * Callback methods
56 */
57
58/** variable selection method of diving heuristic;
59 * finds best candidate variable w.r.t. locking numbers:
60 * - prefer variables that may not be rounded without destroying LP feasibility:
61 * - of these variables, round variable with least number of locks in corresponding direction
62 * - if all remaining fractional variables may be rounded without destroying LP feasibility:
63 * - round variable with least number of locks in opposite of its feasible rounding direction
64 * - binary variables are preferred
65 */
66static
67GCG_DECL_MASTER_DIVINGSELECTVAR(heurSelectVarMastercoefdiving) /*lint --e{715}*/
68{ /*lint --e{715}*/
69 SCIP_VAR** lpcands;
70 SCIP_Real* lpcandssol;
71 SCIP_Real* lpcandsfrac;
72 int nlpcands;
73 SCIP_Bool bestcandmayrounddown;
74 SCIP_Bool bestcandmayroundup;
75 int bestnviolrows; /* number of violated rows for best candidate */
76 SCIP_Real bestcandfrac; /* fractionality of best candidate */
77 int c;
78 SCIP* masterprob = GCGgetMasterprob(gcg);
79
80 /* check preconditions */
81 assert(masterprob != NULL);
82 assert(heur != NULL);
83 assert(bestcand != NULL);
84 assert(bestcandmayround != NULL);
85
86 /* get fractional variables that should be integral */
87 SCIP_CALL( SCIPgetLPBranchCands(masterprob, &lpcands, &lpcandssol, &lpcandsfrac, &nlpcands, NULL, NULL) );
88 assert(lpcands != NULL);
89 assert(lpcandsfrac != NULL);
90 assert(lpcandssol != NULL);
91
92 bestcandmayrounddown = TRUE;
93 bestcandmayroundup = TRUE;
94 bestnviolrows = INT_MAX;
95 bestcandfrac = SCIP_INVALID;
96
97 /* get best candidate */
98 for( c = 0; c < nlpcands; ++c )
99 {
100 SCIP_VAR* var;
101
102 int nviolrows;
103
104 SCIP_Bool mayrounddown;
105 SCIP_Bool mayroundup;
106 SCIP_Real frac;
107
108 int i;
109
110 var = lpcands[c];
111 mayrounddown = SCIPvarMayRoundDown(var);
112 mayroundup = SCIPvarMayRoundUp(var);
113 frac = lpcandsfrac[c];
114
115 /* if the variable is on the tabu list, do not choose it */
116 for( i = 0; i < tabulistsize; ++i )
117 if( tabulist[i] == var )
118 break;
119 if( i < tabulistsize )
120 continue;
121
122 if( mayrounddown || mayroundup )
123 {
124 /* the candidate may be rounded: choose this candidate only, if the best candidate may also be rounded */
125 if( bestcandmayrounddown || bestcandmayroundup )
126 {
127 frac = 1.0 - frac;
128 nviolrows = SCIPvarGetNLocksUp(var);
129
130 /* penalize too small fractions */
131 if( frac < 0.01 )
132 nviolrows *= 100;
133
134 /* prefer decisions on binary variables */
135 if( !SCIPvarIsBinary(var) )
136 nviolrows *= 1000;
137
138 /* check, if candidate is new best candidate */
139 assert( (0.0 < frac && frac < 1.0) || SCIPvarIsBinary(var) );
140 if( nviolrows + frac < bestnviolrows + bestcandfrac )
141 {
142 *bestcand = var;
143 bestnviolrows = nviolrows;
144 bestcandfrac = frac;
145 bestcandmayrounddown = mayrounddown;
146 bestcandmayroundup = mayroundup;
147 }
148 }
149 }
150 else
151 {
152 /* the candidate may not be rounded */
153 frac = 1.0 - frac;
154 nviolrows = SCIPvarGetNLocksUp(var);
155
156 /* penalize too small fractions */
157 if( frac < 0.01 )
158 nviolrows *= 100;
159
160 /* prefer decisions on binary variables */
161 if( !SCIPvarIsBinary(var) )
162 nviolrows *= 100;
163
164 /* check, if candidate is new best candidate: prefer unroundable candidates in any case */
165 assert((0.0 < frac && frac < 1.0) || SCIPvarIsBinary(var));
166 if( bestcandmayrounddown || bestcandmayroundup || nviolrows + frac < bestnviolrows + bestcandfrac )
167 {
168 *bestcand = var;
169 bestnviolrows = nviolrows;
170 bestcandfrac = frac;
171 bestcandmayrounddown = FALSE;
172 bestcandmayroundup = FALSE;
173 }
174 assert(bestcandfrac < SCIP_INVALID);
175 }
176 }
177
178 *bestcandmayround = bestcandmayroundup || bestcandmayrounddown;
179
180 return SCIP_OKAY;
181}
182
183
184/*
185 * heuristic specific interface methods
186 */
187
188/** creates the mastercoefdiving heuristic and includes it in GCG */
190 GCG* gcg /**< GCG data structure */
191 )
192{
193 SCIP_HEUR* heur;
194
195 /* include diving heuristic */
198 HEUR_MAXDEPTH, NULL, NULL, NULL, NULL, NULL, NULL, NULL, heurSelectVarMastercoefdiving, NULL) );
199
200 assert(heur != NULL);
201
202 return SCIP_OKAY;
203}
204
#define SCIP_INVALID
#define SCIP_Bool
#define SCIP_Real
#define SCIP_CALL(x)
#define TRUE
#define FALSE
SCIP * GCGgetMasterprob(GCG *gcg)
Definition: gcg.cpp:99
SCIP_RETCODE SCIPgetLPBranchCands(SCIP *scip, SCIP_VAR ***lpcands, SCIP_Real **lpcandssol, SCIP_Real **lpcandsfrac, int *nlpcands, int *npriolpcands, int *nfracimplvars)
SCIP_Bool SCIPvarMayRoundUp(SCIP_VAR *var)
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
SCIP_Bool SCIPvarMayRoundDown(SCIP_VAR *var)
int SCIPvarGetNLocksUp(SCIP_VAR *var)
SCIP_RETCODE GCGincludeHeurMastercoefdiving(GCG *gcg)
#define HEUR_FREQOFS
#define HEUR_DESC
#define HEUR_DISPCHAR
#define HEUR_MAXDEPTH
#define HEUR_PRIORITY
static GCG_DECL_MASTER_DIVINGSELECTVAR(heurSelectVarMastercoefdiving)
#define HEUR_NAME
#define HEUR_FREQ
master LP diving heuristic that chooses fixings w.r.t. the matrix coefficients
SCIP_RETCODE GCGincludeDivingHeurMaster(GCG *gcg, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, GCG_DECL_MASTER_DIVINGFREE((*divingfree)), GCG_DECL_MASTER_DIVINGINIT((*divinginit)), GCG_DECL_MASTER_DIVINGEXIT((*divingexit)), GCG_DECL_MASTER_DIVINGINITSOL((*divinginitsol)), GCG_DECL_MASTER_DIVINGEXITSOL((*divingexitsol)), GCG_DECL_MASTER_DIVINGINITEXEC((*divinginitexec)), GCG_DECL_MASTER_DIVINGEXITEXEC((*divingexitexec)), GCG_DECL_MASTER_DIVINGSELECTVAR((*divingselectvar)), GCG_MASTER_DIVINGDATA *divingdata)
primal heuristic interface for LP diving heuristics on the master variables
#define NULL
Definition: struct_gcg.h:55
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE