GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
heur_masterfracdiving.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_masterfracdiving.c
30 * @brief master LP diving heuristic that chooses fixings w.r.t. the fractionalities
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
42
43
44#define HEUR_NAME "masterfracdiving"
45#define HEUR_DESC "master LP diving heuristic that chooses fixings w.r.t. the fractionalities"
46#define HEUR_DISPCHAR 'f'
47#define HEUR_PRIORITY -1003000
48#define HEUR_FREQ 10
49#define HEUR_FREQOFS 3
50#define HEUR_MAXDEPTH -1
51
52
53/*
54 * Callback methods
55 */
56
57/** variable selection method of diving heuristic;
58 * finds best candidate variable w.r.t. fractionality:
59 * - prefer variables that may not be rounded without destroying LP feasibility:
60 * - of these variables, round least fractional variable in corresponding direction
61 * - if all remaining fractional variables may be rounded without destroying LP feasibility:
62 * - round variable with least increasing objective value
63 * - binary variables are preferred
64 */
65static
66GCG_DECL_MASTER_DIVINGSELECTVAR(heurSelectVarMasterfracdiving) /*lint --e{715}*/
67{ /*lint --e{715}*/
76 int c;
78
79 /* check preconditions */
81 assert(heur != NULL);
82 assert(bestcand != NULL);
84
85 /* get fractional variables that should be integral */
90
95
96 for( c = 0; c < nlpcands; ++c )
97 {
99 SCIP_Bool mayrounddown;
100 SCIP_Bool mayroundup;
103
104 int i;
105
106 var = lpcands[c];
107
108 mayrounddown = SCIPvarMayRoundDown(var);
109 mayroundup = SCIPvarMayRoundUp(var);
110 frac = lpcandsfrac[c];
112
113 /* if the variable is on the tabu list, do not choose it */
114 for( i = 0; i < tabulistsize; ++i )
115 if( tabulist[i] == var )
116 break;
117 if( i < tabulistsize )
118 continue;
119
120 if( mayrounddown || mayroundup )
121 {
122 /* the candidate may be rounded: choose this candidate only, if the best candidate may also be rounded */
124 {
125 SCIP_Real objgain;
126
127 objgain = (1.0-frac)*obj;
128
129 /* penalize too small fractions */
130 if( ABS(1.0 - frac) < 0.01 )
131 objgain *= 1000.0;
132
133 /* prefer decisions on binary variables */
134 if( !SCIPvarIsBinary(var) )
135 objgain *= 1000.0;
136
137 /* check, if candidate is new best candidate */
138 if( SCIPisLT(masterprob, objgain, bestobjgain) || (SCIPisEQ(masterprob, objgain, bestobjgain) && frac > bestfrac) )
139 {
140 *bestcand = var;
141 bestobjgain = objgain;
142 bestfrac = frac;
143 bestcandmayrounddown = mayrounddown;
144 bestcandmayroundup = mayroundup;
145 }
146 }
147 }
148 else
149 {
150 /* penalize too small fractions */
151 if( ABS(1.0-frac) < 0.01 )
152 frac += 10.0;
153
154 /* prefer decisions on binary variables */
155 if( !SCIPvarIsBinary(var) )
156 frac *= 1000.0;
157
158 /* check, if candidate is new best candidate: prefer unroundable candidates in any case */
160 {
161 *bestcand = var;
162 bestfrac = frac;
165 }
167 }
168 }
169
171
172 return SCIP_OKAY;
173}
174
175
176/*
177 * heuristic specific interface methods
178 */
179
180/** creates the masterfracdiving heuristic and includes it in GCG */
182 GCG* gcg /**< GCG data structure */
183 )
184{
185 SCIP_HEUR* heur;
186
187 /* include diving heuristic */
190 HEUR_MAXDEPTH, NULL, NULL, NULL, NULL, NULL, NULL, NULL, heurSelectVarMasterfracdiving, NULL) );
191
192 assert(heur != NULL);
193
194 return SCIP_OKAY;
195}
196
#define SCIP_INVALID
#define SCIP_Bool
#define SCIP_Real
#define ABS(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_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisEQ(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 SCIPvarIsBinary(SCIP_VAR *var)
SCIP_Bool SCIPvarMayRoundDown(SCIP_VAR *var)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
* bestcandmayround
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
#define HEUR_FREQOFS
#define HEUR_DESC
SCIP_Bool bestcandmayroundup
SCIP_Bool bestcandmayrounddown
#define HEUR_DISPCHAR
#define HEUR_MAXDEPTH
#define HEUR_PRIORITY
SCIP_Real * lpcandssol
#define HEUR_NAME
static SCIP_VAR ** lpcands
int nlpcands
#define HEUR_FREQ
SCIP_VAR * var
SCIP_Real frac
int i
SCIP_Real bestobjgain
SCIP_Real bestfrac
SCIP_Real * lpcandsfrac
SCIP_Real obj
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)
SCIP_VAR ** tabulist
primal heuristic interface for LP diving heuristics on the master variables
SCIP_RETCODE GCGincludeHeurMasterfracdiving(GCG *gcg)
master LP diving heuristic that chooses fixings w.r.t. the fractionalities
#define NULL
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_Heur SCIP_HEUR
#define GCG_DECL_MASTER_DIVINGSELECTVAR(x)
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Var SCIP_VAR