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-2016 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file history.h
17  * @brief internal methods for branching and inference history
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #ifndef __SCIP_HISTORY_H__
25 #define __SCIP_HISTORY_H__
26 
27 
28 #include "scip/def.h"
29 #include "blockmemshell/memory.h"
30 #include "scip/type_retcode.h"
31 #include "scip/type_set.h"
32 #include "scip/type_history.h"
33 
34 #ifdef NDEBUG
35 #include "scip/struct_history.h"
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /** creates an empty history entry */
43 extern
45  SCIP_HISTORY** history, /**< pointer to store branching and inference history */
46  BMS_BLKMEM* blkmem /**< block memory */
47  );
48 
49 /** frees a history entry */
50 extern
51 void SCIPhistoryFree(
52  SCIP_HISTORY** history, /**< pointer to branching and inference history */
53  BMS_BLKMEM* blkmem /**< block memory */
54  );
55 
56 /** resets history entry to zero */
57 extern
58 void SCIPhistoryReset(
59  SCIP_HISTORY* history /**< branching and inference history */
60  );
61 
62 /** unites two history entries by adding the values of the second one to the first one */
63 extern
64 void SCIPhistoryUnite(
65  SCIP_HISTORY* history, /**< branching and inference history */
66  SCIP_HISTORY* addhistory, /**< history values to add to history */
67  SCIP_Bool switcheddirs /**< should the history entries be united with switched directories */
68  );
69 
70 /** updates the pseudo costs for a change of "solvaldelta" in the variable's LP solution value and a change of "objdelta"
71  * in the LP's objective value
72  */
73 extern
75  SCIP_HISTORY* history, /**< branching and inference history */
76  SCIP_SET* set, /**< global SCIP settings */
77  SCIP_Real solvaldelta, /**< difference of variable's new LP value - old LP value */
78  SCIP_Real objdelta, /**< difference of new LP's objective value - old LP's objective value */
79  SCIP_Real weight /**< weight of this update in pseudo cost sum (added to pscostcount) */
80  );
81 
82 
83 /**@defgroup ValueHistory Value based history
84  *
85  * Value based history methods
86  *
87  * @{
88  */
89 
90 /** creates an empty value history */
91 extern
93  SCIP_VALUEHISTORY** valuehistory, /**< pointer to store the value based branching and inference histories */
94  BMS_BLKMEM* blkmem /**< block memory */
95  );
96 
97 /** frees a value history */
98 extern
100  SCIP_VALUEHISTORY** valuehistory, /**< pointer to value based history */
101  BMS_BLKMEM* blkmem /**< block memory */
102  );
103 
104 /** finds for the given domain value the history if it does not exist yet it will be created */
105 extern
107  SCIP_VALUEHISTORY* valuehistory, /**< value based history */
108  BMS_BLKMEM* blkmem, /**< block memory */
109  SCIP_SET* set, /**< global SCIP settings */
110  SCIP_Real value, /**< domain value of interest */
111  SCIP_HISTORY** history /**< pointer to store the history for the given domain value */
112  );
113 
114 /** scales the conflict score values with the given scalar for each value history entry */
115 extern
117  SCIP_VALUEHISTORY* valuehistory, /**< value based history */
118  SCIP_Real scalar /**< scalar to multiply the conflict scores with */
119  );
120 
121 /**@} */
122 
123 /** returns the opposite direction of the given branching direction */
124 extern
126  SCIP_BRANCHDIR dir /**< branching direction */
127  );
128 
129 /** returns the expected dual gain for moving the corresponding variable by "solvaldelta" */
130 extern
132  SCIP_HISTORY* history, /**< branching and inference history */
133  SCIP_Real solvaldelta /**< difference of variable's new LP value - old LP value */
134  );
135 
136 /** returns the variance of pseudo costs about the mean. */
137 extern
139  SCIP_HISTORY* history, /**< branching and inference history */
140  SCIP_BRANCHDIR direction /**< direction of variable: 1 for upwards history, 0 for downwards history */
141  );
142 
143 /** returns the (possible fractional) number of (partial) pseudo cost updates performed on this pseudo cost entry in
144  * the given branching direction
145  */
146 extern
148  SCIP_HISTORY* history, /**< branching and inference history */
149  SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
150  );
151 
152 /** returns whether the pseudo cost entry is empty in the given branching direction (whether no value was added yet) */
153 extern
155  SCIP_HISTORY* history, /**< branching and inference history */
156  SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
157  );
158 
159 /** increases the conflict score of the history entry by the given weight */
160 extern
162  SCIP_HISTORY* history, /**< branching and inference history */
163  SCIP_BRANCHDIR dir, /**< branching direction */
164  SCIP_Real weight /**< weight of this update in conflict score */
165  );
166 
167  /** scales the conflict score values with the given scalar */
168 extern
170  SCIP_HISTORY* history, /**< branching and inference history */
171  SCIP_Real scalar /**< scalar to multiply the conflict scores with */
172  );
173 
174 /** increases the number of active conflicts by one and the overall length of the history entry by the given weight */
175 extern
177  SCIP_HISTORY* history, /**< branching and inference history */
178  SCIP_BRANCHDIR dir, /**< branching direction */
179  SCIP_Real length /**< length of the conflict */
180  );
181 
182 /** gets the number of active conflicts of the history entry */
183 extern
185  SCIP_HISTORY* history, /**< branching and inference history */
186  SCIP_BRANCHDIR dir /**< branching direction */
187  );
188 
189 /** gets the average conflict length of the history entry */
190 extern
192  SCIP_HISTORY* history, /**< branching and inference history */
193  SCIP_BRANCHDIR dir /**< branching direction */
194  );
195 
196 /** increases the number of branchings counter */
197 extern
199  SCIP_HISTORY* history, /**< branching and inference history */
200  SCIP_BRANCHDIR dir, /**< branching direction (downwards, or upwards) */
201  int depth /**< depth at which the bound change took place */
202  );
203 
204 /** increases the number of inferences counter */
205 extern
207  SCIP_HISTORY* history, /**< branching and inference history */
208  SCIP_BRANCHDIR dir, /**< branching direction (downwards, or upwards) */
209  SCIP_Real weight /**< weight of this update in cutoff score */
210  );
211 
212 
213 /** increases the number of cutoffs counter */
214 extern
216  SCIP_HISTORY* history, /**< branching and inference history */
217  SCIP_BRANCHDIR dir, /**< branching direction (downwards, or upwards) */
218  SCIP_Real weight /**< weight of this update in cutoff score */
219  );
220 
221 /** get number of branchings counter */
222 extern
224  SCIP_HISTORY* history, /**< branching and inference history */
225  SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
226  );
227 
228 /** get number of inferences counter */
229 extern
231  SCIP_HISTORY* history, /**< branching and inference history */
232  SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
233  );
234 
235 /** returns the average number of inferences per branching */
236 extern
238  SCIP_HISTORY* history, /**< branching and inference history */
239  SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
240  );
241 
242 /** returns the average number of cutoffs per branching */
243 extern
245  SCIP_HISTORY* history, /**< branching and inference history */
246  SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
247  );
248 
249 /** returns the average depth of bound changes due to branching */
250 extern
252  SCIP_HISTORY* history, /**< branching and inference history */
253  SCIP_BRANCHDIR dir /**< branching direction (downwards, or upwards) */
254  );
255 
256 #ifdef NDEBUG
257 
258 /* In optimized mode, the function calls are overwritten by defines to reduce the number of function calls and
259  * speed up the algorithms.
260  */
261 
262 #define SCIPbranchdirOpposite(dir) \
263  ((dir) == SCIP_BRANCHDIR_DOWNWARDS ? SCIP_BRANCHDIR_UPWARDS \
264  : ((dir) == SCIP_BRANCHDIR_UPWARDS ? SCIP_BRANCHDIR_DOWNWARDS : SCIP_BRANCHDIR_AUTO))
265 #define SCIPhistoryGetPseudocost(history,solvaldelta) \
266  ( (solvaldelta) >= 0.0 ? (solvaldelta) * ((history)->pscostcount[1] > 0.0 \
267  ? (history)->pscostweightedmean[1] : 1.0) \
268  : -(solvaldelta) * ((history)->pscostcount[0] > 0.0 \
269  ? (history)->pscostweightedmean[0] : 1.0) )
270 #define SCIPhistoryGetPseudocostVariance(history, dir) \
271  ( (history)->pscostcount[dir] >= 1.9 ? 1 / ((history)->pscostcount[dir] - 1) \
272  * ((history)->pscostvariance[dir]) \
273  : 0.0)
274 #define SCIPhistoryGetPseudocostCount(history,dir) ((history)->pscostcount[dir])
275 #define SCIPhistoryIsPseudocostEmpty(history,dir) ((history)->pscostcount[dir] == 0.0)
276 #define SCIPhistoryIncVSIDS(history,dir,weight) (history)->vsids[dir] += (weight)
277 #define SCIPhistoryScaleVSIDS(history,scalar) { (history)->vsids[0] *= (scalar); \
278  (history)->vsids[1] *= (scalar); }
279 #define SCIPhistoryIncNActiveConflicts(history,dir,length) { (history)->nactiveconflicts[dir]++; \
280  (history)->conflengthsum[dir] += length; }
281 #define SCIPhistoryGetNActiveConflicts(history,dir) ((history)->nactiveconflicts[dir])
282 #define SCIPhistoryGetAvgConflictlength(history,dir) ((history)->conflengthsum[dir] > 0.0 \
283  ? (SCIP_Real)(history)->nactiveconflicts[dir]/(SCIP_Real)(history)->conflengthsum[dir] : 0.0)
284 #define SCIPhistoryIncNBranchings(history,dir,depth) { (history)->nbranchings[dir]++; \
285  (history)->branchdepthsum[dir] += depth; }
286 #define SCIPhistoryIncInferenceSum(history,dir,weight) (history)->inferencesum[dir] += (weight)
287 #define SCIPhistoryIncCutoffSum(history,dir,weight) (history)->cutoffsum[dir] += (weight)
288 #define SCIPhistoryGetNBranchings(history,dir) ((history)->nbranchings[dir])
289 #define SCIPhistoryGetInferenceSum(history,dir) ((history)->inferencesum[dir])
290 #define SCIPhistoryGetAvgInferences(history,dir) ((history)->nbranchings[dir] > 0 \
291  ? (SCIP_Real)(history)->inferencesum[dir]/(SCIP_Real)(history)->nbranchings[dir] : 0.0)
292 #define SCIPhistoryGetCutoffSum(history,dir) ((history)->cutoffsum[dir])
293 #define SCIPhistoryGetAvgCutoffs(history,dir) ((history)->nbranchings[dir] > 0 \
294  ? (SCIP_Real)(history)->cutoffsum[dir]/(SCIP_Real)(history)->nbranchings[dir] : 0.0)
295 #define SCIPhistoryGetAvgBranchdepth(history,dir) ((history)->nbranchings[dir] > 0 \
296  ? (SCIP_Real)(history)->branchdepthsum[dir]/(SCIP_Real)(history)->nbranchings[dir] : 1.0)
297 
298 #endif
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 
304 #endif
void SCIPhistoryFree(SCIP_HISTORY **history, BMS_BLKMEM *blkmem)
Definition: history.c:55
SCIP_Real SCIPhistoryGetAvgConflictlength(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:555
SCIP_RETCODE SCIPvaluehistoryCreate(SCIP_VALUEHISTORY **valuehistory, BMS_BLKMEM *blkmem)
Definition: history.c:228
void SCIPhistoryIncVSIDS(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, SCIP_Real weight)
Definition: history.c:487
void SCIPhistoryIncCutoffSum(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, SCIP_Real weight)
Definition: history.c:600
SCIP_RETCODE SCIPhistoryCreate(SCIP_HISTORY **history, BMS_BLKMEM *blkmem)
Definition: history.c:40
void SCIPvaluehistoryScaleVSIDS(SCIP_VALUEHISTORY *valuehistory, SCIP_Real scalar)
Definition: history.c:314
void SCIPhistoryIncInferenceSum(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, SCIP_Real weight)
Definition: history.c:584
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
type definitions for global SCIP settings
void SCIPhistoryReset(SCIP_HISTORY *history)
Definition: history.c:67
SCIP_Real SCIPhistoryGetPseudocost(SCIP_HISTORY *history, SCIP_Real solvaldelta)
Definition: history.c:423
type definitions for return codes for SCIP methods
SCIP_Real SCIPhistoryGetAvgCutoffs(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:668
enum SCIP_BranchDir SCIP_BRANCHDIR
Definition: type_history.h:39
SCIP_Real SCIPhistoryGetAvgBranchdepth(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:681
SCIP_RETCODE SCIPvaluehistoryFind(SCIP_VALUEHISTORY *valuehistory, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_Real value, SCIP_HISTORY **history)
Definition: history.c:269
void SCIPhistoryScaleVSIDS(SCIP_HISTORY *history, SCIP_Real scalar)
Definition: history.c:501
void SCIPvaluehistoryFree(SCIP_VALUEHISTORY **valuehistory, BMS_BLKMEM *blkmem)
Definition: history.c:247
void SCIPhistoryIncNActiveConflicts(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, SCIP_Real length)
Definition: history.c:526
SCIP_Real SCIPhistoryGetPseudocostVariance(SCIP_HISTORY *history, SCIP_BRANCHDIR direction)
Definition: history.c:437
void SCIPhistoryUnite(SCIP_HISTORY *history, SCIP_HISTORY *addhistory, SCIP_Bool switcheddirs)
Definition: history.c:96
SCIP_Real SCIPhistoryGetPseudocostCount(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:461
SCIP_Bool SCIPhistoryIsPseudocostEmpty(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:474
SCIP_Longint SCIPhistoryGetNActiveConflicts(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:542
#define SCIP_Bool
Definition: def.h:53
void SCIPhistoryUpdatePseudocost(SCIP_HISTORY *history, SCIP_SET *set, SCIP_Real solvaldelta, SCIP_Real objdelta, SCIP_Real weight)
Definition: history.c:159
SCIP_Longint SCIPhistoryGetNBranchings(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:616
datastructures for branching and inference history
SCIP_BRANCHDIR SCIPbranchdirOpposite(SCIP_BRANCHDIR dir)
Definition: history.c:414
SCIP_Real SCIPhistoryGetAvgInferences(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:642
#define SCIP_Real
Definition: def.h:127
type definitions for branching and inference history
SCIP_Real SCIPhistoryGetInferenceSum(SCIP_HISTORY *history, SCIP_BRANCHDIR dir)
Definition: history.c:629
#define SCIP_Longint
Definition: def.h:112
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:392
void SCIPhistoryIncNBranchings(SCIP_HISTORY *history, SCIP_BRANCHDIR dir, int depth)
Definition: history.c:568
memory allocation routines