Scippy

SCIP

Solving Constraint Integer Programs

history.h
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* SCIP --- Solving Constraint Integer Programs */
5/* */
6/* Copyright (c) 2002-2025 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file history.h
26 * @ingroup INTERNALAPI
27 * @brief internal methods for branching and inference history
28 * @author Tobias Achterberg
29 * @author Timo Berthold
30 */
31
32/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
33
34#ifndef __SCIP_HISTORY_H__
35#define __SCIP_HISTORY_H__
36
37
38#include "scip/def.h"
40#include "scip/type_retcode.h"
41#include "scip/type_set.h"
42#include "scip/type_history.h"
43
44#ifdef NDEBUG
45#include "scip/struct_history.h"
46#endif
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/** creates an empty history entry */
54 SCIP_HISTORY** history, /**< pointer to store branching and inference history */
55 BMS_BLKMEM* blkmem /**< block memory */
56 );
57
58/** frees a history entry */
60 SCIP_HISTORY** history, /**< pointer to branching and inference history */
61 BMS_BLKMEM* blkmem /**< block memory */
62 );
63
64/** resets history entry to zero */
66 SCIP_HISTORY* history /**< branching and inference history */
67 );
68
69/** unites two history entries by adding the values of the second one to the first one */
71 SCIP_HISTORY* history, /**< branching and inference history */
72 SCIP_HISTORY* addhistory, /**< history values to add to history */
73 SCIP_Bool switcheddirs /**< should the history entries be united with switched directories */
74 );
75
76/** updates the pseudo costs for a change of "solvaldelta" in the variable's LP solution value and a change of "objdelta"
77 * in the LP's objective value
78 */
80 SCIP_HISTORY* history, /**< branching and inference history */
81 SCIP_SET* set, /**< global SCIP settings */
82 SCIP_Real solvaldelta, /**< difference of variable's new LP value - old LP value */
83 SCIP_Real objdelta, /**< difference of new LP's objective value - old LP's objective value */
84 SCIP_Real weight /**< weight of this update in pseudo cost sum (added to pscostcount) */
85 );
86
87/** updates the ancestral pseudo costs for a change of "solvaldelta" in the variable's LP solution value and a change of
88 * "objdelta" in the LP's objective value
89 */
91 SCIP_HISTORY* history, /**< branching and inference history */
92 SCIP_SET* set, /**< global SCIP settings */
93 SCIP_Real solvaldelta, /**< difference of variable's new LP value - old LP value */
94 SCIP_Real objdelta, /**< difference of new LP's objective value - old LP's objective value */
95 SCIP_Real weight /**< weight of this update in discounted pseudo cost sum (added to ancpscostcount) */
96 );
97
98
99/**@defgroup ValueHistory Value Based History
100 * @ingroup INTERNALAPI
101 * @brief Value based history methods
102 *
103 * @{
104 */
105
106/** creates an empty value history */
108 SCIP_VALUEHISTORY** valuehistory, /**< pointer to store the value based branching and inference histories */
109 BMS_BLKMEM* blkmem /**< block memory */
110 );
111
112/** frees a value history */
114 SCIP_VALUEHISTORY** valuehistory, /**< pointer to value based history */
115 BMS_BLKMEM* blkmem /**< block memory */
116 );
117
118/** finds for the given domain value the history if it does not exist yet it will be created */
120 SCIP_VALUEHISTORY* valuehistory, /**< value based history */
121 BMS_BLKMEM* blkmem, /**< block memory */
122 SCIP_SET* set, /**< global SCIP settings */
123 SCIP_Real value, /**< domain value of interest */
124 SCIP_HISTORY** history /**< pointer to store the history for the given domain value */
125 );
126
127/** scales the conflict score values with the given scalar for each value history entry */
129 SCIP_VALUEHISTORY* valuehistory, /**< value based history */
130 SCIP_Real scalar /**< scalar to multiply the conflict scores with */
131 );
132
133/**@} */
134
135/** returns the opposite direction of the given branching direction */
137 SCIP_BRANCHDIR dir /**< branching direction */
138 );
139
140/** returns the expected dual gain for moving the corresponding variable by "solvaldelta" */
142 SCIP_HISTORY* history, /**< branching and inference history */
143 SCIP_Real solvaldelta /**< difference of variable's new LP value - old LP value */
144 );
145
146/** returns the expected ancestral dual gain for moving the corresponding variable by "solvaldelta" */
148 SCIP_HISTORY* history, /**< branching and inference history */
149 SCIP_Real solvaldelta /**< difference of variable's new LP value - old LP value */
150 );
151
152/** returns the variance of pseudo costs about the mean. */
154 SCIP_HISTORY* history, /**< branching and inference history */
155 SCIP_BRANCHDIR direction /**< direction of variable: 1 for upwards history, 0 for downwards history */
156 );
157
158/** returns the (possible fractional) number of (partial) pseudo cost updates performed on this pseudo cost entry in
159 * the given branching direction
160 */
162 SCIP_HISTORY* history, /**< branching and inference history */
163 SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
164 );
165
166/** returns the (possible fractional) number of (partial) ancestral pseudo cost updates performed on this pseudo cost entry in
167 * the given branching direction
168 */
170 SCIP_HISTORY* history, /**< branching and inference history */
171 SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
172 );
173
174/** returns whether the pseudo cost entry is empty in the given branching direction (whether no value was added yet) */
176 SCIP_HISTORY* history, /**< branching and inference history */
177 SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
178 );
179
180/** returns whether the ancestral pseudo cost entry is empty in the given branching direction (whether no value was added yet) */
182 SCIP_HISTORY* history, /**< branching and inference history */
183 SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
184 );
185
186/** increases the conflict score of the history entry by the given weight */
188 SCIP_HISTORY* history, /**< branching and inference history */
189 SCIP_BRANCHDIR dir, /**< branching direction */
190 SCIP_Real weight /**< weight of this update in conflict score */
191 );
192
193 /** scales the conflict score values with the given scalar */
195 SCIP_HISTORY* history, /**< branching and inference history */
196 SCIP_Real scalar /**< scalar to multiply the conflict scores with */
197 );
198
199/** increases the number of active conflicts by one and the overall length of the history entry by the given weight */
201 SCIP_HISTORY* history, /**< branching and inference history */
202 SCIP_BRANCHDIR dir, /**< branching direction */
203 SCIP_Real length /**< length of the conflict */
204 );
205
206/** gets the number of active conflicts of the history entry */
208 SCIP_HISTORY* history, /**< branching and inference history */
209 SCIP_BRANCHDIR dir /**< branching direction */
210 );
211
212/** increases the number of branchings counter */
214 SCIP_HISTORY* history, /**< branching and inference history */
215 SCIP_BRANCHDIR dir, /**< branching direction (downwards, or upwards) */
216 int depth /**< depth at which the bound change took place */
217 );
218
219/** increases the number of inferences counter */
221 SCIP_HISTORY* history, /**< branching and inference history */
222 SCIP_BRANCHDIR dir, /**< branching direction (downwards, or upwards) */
223 SCIP_Real weight /**< weight of this update in cutoff score */
224 );
225
226
227/** increases the number of cutoffs counter */
229 SCIP_HISTORY* history, /**< branching and inference history */
230 SCIP_BRANCHDIR dir, /**< branching direction (downwards, or upwards) */
231 SCIP_Real weight /**< weight of this update in cutoff score */
232 );
233
234/** get number of branchings counter */
236 SCIP_HISTORY* history, /**< branching and inference history */
237 SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
238 );
239
240/** returns the average number of inferences per branching */
242 SCIP_HISTORY* history, /**< branching and inference history */
243 SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
244 );
245
246/** returns the average number of cutoffs per branching */
248 SCIP_HISTORY* history, /**< branching and inference history */
249 SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
250 );
251
252/** returns the average depth of bound changes due to branching */
254 SCIP_HISTORY* history, /**< branching and inference history */
255 SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
256 );
257
258/** returns true if the given history contains a valid ratio */
260 SCIP_HISTORY* history /**< branching and inference history */
261 );
262
263/** returns the most recent ratio computed given the variable history */
265 SCIP_HISTORY* history /**< branching and inference history */
266 );
267
268/** returns the most recent value of r/l used to compute this variable's ratio */
270 SCIP_HISTORY* history /**< branching and inference history */
271 );
272
273/** returns the average efficacy value for the GMI cut produced by this variable */
275 SCIP_HISTORY* history /**< branching and inference history */
276 );
277
278/** increases the average efficacy value for the GMI cut produced by this variable */
280 SCIP_HISTORY* history, /**< branching and inference history */
281 SCIP_Real gmieff /**< normalized efficacy value of a cut which will increase gmieff */
282 );
283
284/** returns the most recent efficacy value for the GMI cut produced by this variable */
286 SCIP_HISTORY* history /**< branching and inference history */
287 );
288
289/** sets the new most recent efficacy value for the GMI cut produced by this variable */
291 SCIP_HISTORY* history, /**< branching and inference history */
292 SCIP_Real gmieff /**< Efficacy of GMI cut produced from simplex tableau row of this var */
293 );
294
295/** sets the ratio history for a particular variable */
297 SCIP_HISTORY* history, /**< branching and inference history */
298 SCIP_Bool valid, /**< True iff the ratio computed is valid */
299 SCIP_Real ratio, /**< Ratio of the characteristic polynomial with gains (1, rightgain/leftgain) */
300 SCIP_Real balance /**< The value of rightgain/leftgain */
301 );
302
303#ifdef NDEBUG
304
305/* In optimized mode, the function calls are overwritten by defines to reduce the number of function calls and
306 * speed up the algorithms.
307 */
308
309#define SCIPbranchdirOpposite(dir) \
310 ((dir) == SCIP_BRANCHDIR_DOWNWARDS ? SCIP_BRANCHDIR_UPWARDS \
311 : ((dir) == SCIP_BRANCHDIR_UPWARDS ? SCIP_BRANCHDIR_DOWNWARDS : SCIP_BRANCHDIR_AUTO))
312#define SCIPhistoryGetPseudocost(history,solvaldelta) \
313 ( (solvaldelta) >= 0.0 ? (solvaldelta) * ((history)->pscostcount[1] > 0.0 \
314 ? (history)->pscostweightedmean[1] : 1.0) \
315 : -(solvaldelta) * ((history)->pscostcount[0] > 0.0 \
316 ? (history)->pscostweightedmean[0] : 1.0) )
317#define SCIPhistoryGetAncPseudocost(history,solvaldelta) \
318 ( (solvaldelta) >= 0.0 ? (solvaldelta) * ((history)->ancpscostcount[1] > 0.0 \
319 ? (history)->ancpscostweightedmean[1] : 1.0) \
320 : -(solvaldelta) * ((history)->ancpscostcount[0] > 0.0 \
321 ? (history)->ancpscostweightedmean[0] : 1.0) )
322#define SCIPhistoryGetPseudocostVariance(history, dir) \
323 ( (history)->pscostcount[dir] >= 1.9 ? 1 / ((history)->pscostcount[dir] - 1) \
324 * ((history)->pscostvariance[dir]) \
325 : 0.0)
326#define SCIPhistoryGetPseudocostCount(history,dir) ((history)->pscostcount[dir])
327#define SCIPhistoryGetAncPseudocostCount(history,dir) ((history)->ancpscostcount[dir])
328#define SCIPhistoryIsPseudocostEmpty(history,dir) ((history)->pscostcount[dir] == 0.0)
329#define SCIPhistoryIsAncPseudocostEmpty(history,dir) ((history)->ancpscostcount[dir] == 0.0)
330#define SCIPhistoryIncVSIDS(history,dir,weight) (history)->vsids[dir] += (weight)
331#define SCIPhistoryScaleVSIDS(history,scalar) { (history)->vsids[0] *= (scalar); \
332 (history)->vsids[1] *= (scalar); }
333#define SCIPhistoryIncNActiveConflicts(history,dir,length) { (history)->nactiveconflicts[dir]++; \
334 (history)->conflengthsum[dir] += length; }
335#define SCIPhistoryGetNActiveConflicts(history,dir) ((history)->nactiveconflicts[dir])
336#define SCIPhistoryIncNBranchings(history,dir,depth) { (history)->nbranchings[dir]++; \
337 (history)->branchdepthsum[dir] += depth; }
338#define SCIPhistoryIncInferenceSum(history,dir,weight) (history)->inferencesum[dir] += (weight)
339#define SCIPhistoryIncCutoffSum(history,dir,weight) (history)->cutoffsum[dir] += (weight)
340#define SCIPhistoryGetNBranchings(history,dir) ((history)->nbranchings[dir])
341#define SCIPhistoryGetAvgInferences(history,dir) ((history)->nbranchings[dir] > 0 \
342 ? (SCIP_Real)(history)->inferencesum[dir]/(SCIP_Real)(history)->nbranchings[dir] : 0.0)
343#define SCIPhistoryGetAvgCutoffs(history,dir) ((history)->nbranchings[dir] > 0 \
344 ? (SCIP_Real)(history)->cutoffsum[dir]/(SCIP_Real)(history)->nbranchings[dir] : 0.0)
345#define SCIPhistoryGetAvgBranchdepth(history,dir) ((history)->nbranchings[dir] > 0 \
346 ? (SCIP_Real)(history)->branchdepthsum[dir]/(SCIP_Real)(history)->nbranchings[dir] : 1.0)
347#define SCIPhistoryIsRatioValid(history) ((history)->ratiovalid)
348#define SCIPhistoryGetLastRatio(history) ((history)->ratio)
349#define SCIPhistorySetRatioHistory(history,newvalid,newratio,newbalance) (history)->ratiovalid = newvalid, \
350 (history)->ratio = newratio, (history)->balance = newbalance
351#define SCIPhistoryGetLastBalance(history) ((history)->balance)
352#define SCIPhistoryGetLastGMIeff(history) ((history)->gmieff)
353#define SCIPhistorySetLastGMIeff(history,newgmieff) (history)->gmieff = newgmieff
354#define SCIPhistoryGetAvgGMIeff(history) ((history)->ngmi > 0 \
355 ? (SCIP_Real)(history)->gmieffsum/(SCIP_Real)(history)->ngmi : 0.0)
356#define SCIPhistoryIncGMIeffSum(history, newgmieff) { (history)->gmieffsum += newgmieff; \
357 (history)->ngmi += 1; }
358
359#endif
360
361#ifdef __cplusplus
362}
363#endif
364
365#endif
common defines and data types used in all packages of SCIP
#define SCIP_Longint
Definition: def.h:141
#define SCIP_Bool
Definition: def.h:91
#define SCIP_Real
Definition: def.h:156
SCIP_RETCODE SCIPvaluehistoryCreate(SCIP_VALUEHISTORY **valuehistory, BMS_BLKMEM *blkmem)
Definition: history.c:323
SCIP_RETCODE SCIPvaluehistoryFind(SCIP_VALUEHISTORY *valuehistory, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_Real value, SCIP_HISTORY **history)
Definition: history.c:364
void SCIPvaluehistoryFree(SCIP_VALUEHISTORY **valuehistory, BMS_BLKMEM *blkmem)
Definition: history.c:342
void SCIPvaluehistoryScaleVSIDS(SCIP_VALUEHISTORY *valuehistory, SCIP_Real scalar)
Definition: history.c:409
void SCIPhistoryReset(SCIP_HISTORY *history)
Definition: history.c:78
SCIP_Real SCIPhistoryGetPseudocost(SCIP_HISTORY *history, SCIP_Real solvaldelta)
Definition: history.c:529
SCIP_Real SCIPhistoryGetAvgInferences(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:790
void SCIPhistorySetRatioHistory(SCIP_HISTORY *history, SCIP_Bool valid, SCIP_Real ratio, SCIP_Real balance)
Definition: history.c:918
SCIP_Longint SCIPhistoryGetNActiveConflicts(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:690
SCIP_Longint SCIPhistoryGetNBranchings(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:764
SCIP_Real SCIPhistoryGetAvgCutoffs(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:816
SCIP_RETCODE SCIPhistoryCreate(SCIP_HISTORY **history, BMS_BLKMEM *blkmem)
Definition: history.c:51
SCIP_Real SCIPhistoryGetAncPseudocostCount(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:596
void SCIPhistorySetLastGMIeff(SCIP_HISTORY *history, SCIP_Real gmieff)
Definition: history.c:907
void SCIPhistoryUpdateAncPseudocost(SCIP_HISTORY *history, SCIP_SET *set, SCIP_Real solvaldelta, SCIP_Real objdelta, SCIP_Real weight)
Definition: history.c:255
SCIP_Real SCIPhistoryGetLastRatio(SCIP_HISTORY *history)
Definition: history.c:852
void SCIPhistoryIncInferenceSum(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, SCIP_Real weight)
Definition: history.c:732
SCIP_Real SCIPhistoryGetAncPseudocost(SCIP_HISTORY *history, SCIP_Real solvaldelta)
Definition: history.c:543
SCIP_Real SCIPhistoryGetPseudocostCount(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:581
SCIP_Bool SCIPhistoryIsPseudocostEmpty(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:609
SCIP_Bool SCIPhistoryIsAncPseudocostEmpty(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:622
SCIP_Real SCIPhistoryGetPseudocostVariance(SCIP_HISTORY *history, SCIP_BRANCHDIR direction)
Definition: history.c:557
void SCIPhistoryIncNActiveConflicts(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, SCIP_Real length)
Definition: history.c:674
void SCIPhistoryScaleVSIDS(SCIP_HISTORY *history, SCIP_Real scalar)
Definition: history.c:649
void SCIPhistoryIncCutoffSum(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, SCIP_Real weight)
Definition: history.c:748
void SCIPhistoryIncNBranchings(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, int depth)
Definition: history.c:716
void SCIPhistoryUpdatePseudocost(SCIP_HISTORY *history, SCIP_SET *set, SCIP_Real solvaldelta, SCIP_Real objdelta, SCIP_Real weight)
Definition: history.c:191
SCIP_Bool SCIPhistoryIsRatioValid(SCIP_HISTORY *history)
Definition: history.c:842
SCIP_Real SCIPhistoryGetAvgBranchdepth(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:829
SCIP_Real SCIPhistoryGetLastBalance(SCIP_HISTORY *history)
Definition: history.c:863
SCIP_Real SCIPhistoryGetLastGMIeff(SCIP_HISTORY *history)
Definition: history.c:897
SCIP_Real SCIPhistoryGetAvgGMIeff(SCIP_HISTORY *history)
Definition: history.c:874
void SCIPhistoryFree(SCIP_HISTORY **history, BMS_BLKMEM *blkmem)
Definition: history.c:66
void SCIPhistoryUnite(SCIP_HISTORY *history, SCIP_HISTORY *addhistory, SCIP_Bool switcheddirs)
Definition: history.c:117
void SCIPhistoryIncGMIeffSum(SCIP_HISTORY *history, SCIP_Real gmieff)
Definition: history.c:884
SCIP_BRANCHDIR SCIPbranchdirOpposite(SCIP_BRANCHDIR dir)
Definition: history.c:520
void SCIPhistoryIncVSIDS(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, SCIP_Real weight)
Definition: history.c:635
memory allocation routines
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:437
datastructures for branching and inference history
Definition: heur_padm.c:135
type definitions for branching and inference history
enum SCIP_BranchDir SCIP_BRANCHDIR
Definition: type_history.h:48
type definitions for return codes for SCIP methods
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
type definitions for global SCIP settings