Scippy

GCG

Branch-and-Price & Column Generation for Everyone

heur_mastervecldiving.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_mastervecldiving.c
30 * @brief master LP diving heuristic that rounds variables with long column vectors
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 "mastervecldiving"
45#define HEUR_DESC "master LP diving heuristic that rounds variables with long column vectors"
46#define HEUR_DISPCHAR 'v'
47#define HEUR_PRIORITY -1003100
48#define HEUR_FREQ 10
49#define HEUR_FREQOFS 4
50#define HEUR_MAXDEPTH -1
51
52
53/*
54 * Callback methods
55 */
56
57
58/** variable selection method of diving heuristic;
59 * finds best candidate variable w.r.t. vector length:
60 * - round variables in direction where objective value gets worse; for zero objective coefficient, round upwards
61 * - round variable with least objective value deficit per row the variable appears in
62 * (we want to "fix" as many rows as possible with the least damage to the objective function)
63 */
64static
65GCG_DECL_MASTER_DIVINGSELECTVAR(heurSelectVarMastervecldiving) /*lint --e{715}*/
66{ /*lint --e{715}*/
67 SCIP_VAR** lpcands;
68 SCIP_Real* lpcandssol;
69 SCIP_Real* lpcandsfrac;
70 int nlpcands;
71 SCIP_Real bestscore;
72 int c;
73 SCIP* masterprob = GCGgetMasterprob(gcg);
74
75 /* check preconditions */
76 assert(masterprob != NULL);
77 assert(heur != NULL);
78 assert(bestcand != NULL);
79 assert(bestcandmayround != NULL);
80
81 /* get fractional variables that should be integral */
82 SCIP_CALL( SCIPgetLPBranchCands(masterprob, &lpcands, &lpcandssol, &lpcandsfrac, &nlpcands, NULL, NULL) );
83 assert(lpcands != NULL);
84 assert(lpcandsfrac != NULL);
85 assert(lpcandssol != NULL);
86
87 *bestcandmayround = TRUE;
88 bestscore = SCIP_REAL_MAX;
89
90 /* get best candidate */
91 for( c = 0; c < nlpcands; ++c )
92 {
93 SCIP_VAR* var;
94
95 SCIP_Real obj;
96 SCIP_Real objdelta;
97 SCIP_Real frac;
98 SCIP_Real score;
99 int colveclen;
100
101 int i;
102
103 var = lpcands[c];
104
105 /* if the variable is on the tabu list, do not choose it */
106 for( i = 0; i < tabulistsize; ++i )
107 if( tabulist[i] == var )
108 break;
109 if( i < tabulistsize )
110 continue;
111
112 frac = lpcandsfrac[c];
113 obj = SCIPvarGetObj(var);
114 objdelta = (1.0 - frac) * obj;
115
117
118 /* check whether the variable is roundable */
119 *bestcandmayround = *bestcandmayround && (SCIPvarMayRoundDown(var) || SCIPvarMayRoundUp(var));
120
121 /* smaller score is better */
122 score = (objdelta + SCIPsumepsilon(masterprob))/((SCIP_Real)colveclen+1.0);
123
124 /* penalize negative scores (i.e. improvements in the objective) */
125 if( score <= 0.0 )
126 score *= 100.0;
127
128 /* prefer decisions on binary variables */
130 score *= 1000.0;
131
132 /* check, if candidate is new best candidate */
133 if( score < bestscore )
134 {
135 *bestcand = var;
136 bestscore = score;
137 }
138 }
139
140 return SCIP_OKAY;
141}
142
143
144/*
145 * heuristic specific interface methods
146 */
147
148/** creates the mastervecldiving heuristic and includes it in GCG */
150 GCG* gcg /**< GCG data structure */
151 )
152{
153 SCIP_HEUR* heur;
154
155 /* include diving heuristic */
158 HEUR_MAXDEPTH, NULL, NULL, NULL, NULL, NULL, NULL, NULL, heurSelectVarMastervecldiving, NULL) );
159
160 assert(heur != NULL);
161
162 return SCIP_OKAY;
163}
164
#define SCIP_REAL_MAX
#define SCIP_Real
#define SCIP_CALL(x)
#define TRUE
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)
int SCIPcolGetNNonz(SCIP_COL *col)
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
SCIP_Bool SCIPvarMayRoundUp(SCIP_VAR *var)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
SCIP_Bool SCIPvarMayRoundDown(SCIP_VAR *var)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
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 HEUR_FREQOFS
#define HEUR_DESC
#define HEUR_DISPCHAR
#define HEUR_MAXDEPTH
#define HEUR_PRIORITY
#define HEUR_NAME
SCIP_RETCODE GCGincludeHeurMastervecldiving(GCG *gcg)
static GCG_DECL_MASTER_DIVINGSELECTVAR(heurSelectVarMastervecldiving)
#define HEUR_FREQ
master LP diving heuristic that rounds variables with long column vectors
#define NULL
Definition: struct_gcg.h:55
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE
SCIP_VARTYPE_BINARY
SCIP_VARSTATUS_COLUMN