Scippy

SCIP

Solving Constraint Integer Programs

def.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-2022 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 visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file def.h
17  * @ingroup INTERNALAPI
18  * @brief common defines and data types used in all packages of SCIP
19  * @author Tobias Achterberg
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #ifndef __SCIP_DEF_H__
25 #define __SCIP_DEF_H__
26 
27 #ifdef __cplusplus
28 #define __STDC_LIMIT_MACROS
29 #define __STDC_CONSTANT_MACROS
30 #endif
31 
32 #include <stdio.h>
33 #include <stdint.h>
34 #include <math.h>
35 #include <limits.h>
36 #include <float.h>
37 #include <assert.h>
38 
39 /*
40  * include build configuration flags
41  */
42 #ifndef NO_CONFIG_HEADER
43 #include "scip/config.h"
44 #include "scip/scip_export.h"
45 #endif
46 
47 /*
48  * GNU COMPILER VERSION define
49  */
50 #ifdef __GNUC__
51 #ifndef GCC_VERSION
52 #define GCC_VERSION (__GNUC__ * 100 \
53  + __GNUC_MINOR__ * 10 \
54  + __GNUC_PATCHLEVEL__)
55 #endif
56 #endif
57 
58 /*
59  * define whether compiler allows variadic macros
60  * __STDC_VERSION__ only exists for C code
61  * added the extra check using the GCC_VERSION to enable variadic macros also with C++ code with GCC atleast
62  *
63  */
64 #if defined(_MSC_VER) || ( __STDC_VERSION__ >= 199901L ) || ( GCC_VERSION >= 480 )
65 #define SCIP_HAVE_VARIADIC_MACROS 1
66 #endif
67 
68 /** get the first parameter and all-but-the-first arguments from variadic arguments
69  *
70  * normally, SCIP_VARARGS_FIRST_ should be sufficient
71  * the SCIP_VARARGS_FIRST_/SCIP_VARARGS_FIRST kludge is to work around a bug in MSVC (https://stackoverflow.com/questions/4750688/how-to-single-out-the-first-parameter-sent-to-a-macro-taking-only-a-variadic-par)
72  */
73 #define SCIP_VARARGS_FIRST_(firstarg, ...) firstarg
74 #define SCIP_VARARGS_FIRST(args) SCIP_VARARGS_FIRST_ args
75 
76 /** get all but the first parameter from variadic arguments */
77 #define SCIP_VARARGS_REST(firstarg, ...) __VA_ARGS__
78 
79 /*
80  * Boolean values
81  */
82 
83 #ifndef SCIP_Bool
84 #define SCIP_Bool unsigned int /**< type used for Boolean values */
85 #ifndef TRUE
86 #define TRUE 1 /**< Boolean value TRUE */
87 #define FALSE 0 /**< Boolean value FALSE */
88 #endif
89 #endif
90 
91 #ifndef SCIP_Shortbool
92 #define SCIP_Shortbool uint8_t /**< type used for Boolean values with less space */
93 #endif
94 
95 /*
96  * Add some macros for differing functions on Windows
97  */
98 #if defined(_WIN32) || defined(_WIN64)
99 
100 #define strcasecmp _stricmp
101 #define strncasecmp _strnicmp
102 #define getcwd _getcwd
103 #endif
104 
105 /*
106  * Define the marco SCIP_EXPORT if it is not included from the generated header
107  */
108 #ifndef SCIP_EXPORT
109 #if defined(_WIN32) || defined(_WIN64)
110 #define SCIP_EXPORT __declspec(dllexport)
111 #elif defined(__GNUC__) && __GNUC__ >= 4
112 #define SCIP_EXPORT __attribute__((__visibility__("default")))
113 #else
114 #define SCIP_EXPORT
115 #endif
116 #endif
117 
118 /* define INLINE */
119 #ifndef INLINE
120 #if defined(_WIN32) || defined(__STDC__)
121 #define INLINE __inline
122 #else
123 #define INLINE inline
124 #endif
125 #endif
126 
127 
128 
129 #include "scip/type_retcode.h"
130 #include "scip/type_message.h"
131 #include "scip/pub_message.h"
132 
133 #ifdef __cplusplus
134 extern "C" {
135 #endif
136 
137 
138 #define SCIP_VERSION 800 /**< SCIP version number (multiplied by 100 to get integer number) */
139 #define SCIP_SUBVERSION 0 /**< SCIP sub version number */
140 #define SCIP_APIVERSION 104 /**< SCIP API version number */
141 #define SCIP_COPYRIGHT "Copyright (C) 2002-2021 Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)"
142 
143 
144 /*
145  * CIP format variable characters
146  */
147 
148 #define SCIP_VARTYPE_BINARY_CHAR 'B'
149 #define SCIP_VARTYPE_INTEGER_CHAR 'I'
150 #define SCIP_VARTYPE_IMPLINT_CHAR 'M'
151 #define SCIP_VARTYPE_CONTINUOUS_CHAR 'C'
152 
153 /*
154  * Long Integer values
155  */
156 
157 #ifndef LLONG_MAX
158 #define LLONG_MAX 9223372036854775807LL
159 #define LLONG_MIN (-LLONG_MAX - 1LL)
160 #endif
161 
162 #define SCIP_Longint long long /**< type used for long integer values */
163 #define SCIP_LONGINT_MAX LLONG_MAX
164 #define SCIP_LONGINT_MIN LLONG_MIN
165 #ifndef SCIP_LONGINT_FORMAT
166 #if defined(_WIN32) || defined(_WIN64)
167 #define SCIP_LONGINT_FORMAT "I64d"
168 #else
169 #define SCIP_LONGINT_FORMAT "lld"
170 #endif
171 #endif
172 
173 /*
174  * Floating point values
175  */
176 
177 #define SCIP_Real double /**< type used for floating point values */
178 #define SCIP_REAL_MAX (SCIP_Real)DBL_MAX
179 #define SCIP_REAL_MIN -(SCIP_Real)DBL_MAX
180 #define SCIP_REAL_FORMAT "lf"
181 
182 #define SCIP_DEFAULT_INFINITY 1e+20 /**< default value considered to be infinity */
183 #define SCIP_DEFAULT_EPSILON 1e-09 /**< default upper bound for floating points to be considered zero */
184 #define SCIP_DEFAULT_SUMEPSILON 1e-06 /**< default upper bound for sums of floating points to be considered zero */
185 #define SCIP_DEFAULT_FEASTOL 1e-06 /**< default feasibility tolerance for constraints */
186 #define SCIP_DEFAULT_CHECKFEASTOLFAC 1.0 /**< default factor to change the feasibility tolerance when testing the best solution for feasibility (after solving process) */
187 #define SCIP_DEFAULT_LPFEASTOLFACTOR 1.0 /**< default factor w.r.t. primal feasibility tolerance that determines default (and maximal) primal feasibility tolerance of LP solver */
188 #define SCIP_DEFAULT_DUALFEASTOL 1e-07 /**< default feasibility tolerance for reduced costs */
189 #define SCIP_DEFAULT_BARRIERCONVTOL 1e-10 /**< default convergence tolerance used in barrier algorithm */
190 #define SCIP_DEFAULT_BOUNDSTREPS 0.05 /**< default minimal relative improve for strengthening bounds */
191 #define SCIP_DEFAULT_PSEUDOCOSTEPS 1e-01 /**< default minimal variable distance value to use for pseudo cost updates */
192 #define SCIP_DEFAULT_PSEUDOCOSTDELTA 1e-04 /**< default minimal objective distance value to use for pseudo cost updates */
193 #define SCIP_DEFAULT_RECOMPFAC 1e+07 /**< default minimal decrease factor that causes the recomputation of a value (e.g., pseudo objective) instead of an update */
194 #define SCIP_DEFAULT_HUGEVAL 1e+15 /**< values larger than this are considered huge and should be handled separately (e.g., in activity computation) */
195 #define SCIP_MAXEPSILON 1e-03 /**< maximum value for any numerical epsilon */
196 #define SCIP_MINEPSILON 1e-20 /**< minimum value for any numerical epsilon */
197 #define SCIP_INVALID (double)1e+99 /**< floating point value is not valid */
198 #define SCIP_UNKNOWN (double)1e+98 /**< floating point value is not known (in primal solution) */
199 #define SCIP_INTERVAL_INFINITY (double)1e+300 /**< infinity value for interval computations */
200 
201 #define REALABS(x) (fabs(x))
202 #define EPSEQ(x,y,eps) (REALABS((x)-(y)) <= (eps))
203 #define EPSLT(x,y,eps) ((x)-(y) < -(eps))
204 #define EPSLE(x,y,eps) ((x)-(y) <= (eps))
205 #define EPSGT(x,y,eps) ((x)-(y) > (eps))
206 #define EPSGE(x,y,eps) ((x)-(y) >= -(eps))
207 #define EPSZ(x,eps) (REALABS(x) <= (eps))
208 #define EPSP(x,eps) ((x) > (eps))
209 #define EPSN(x,eps) ((x) < -(eps))
210 #define EPSFLOOR(x,eps) (floor((x)+(eps)))
211 #define EPSCEIL(x,eps) (ceil((x)-(eps)))
212 #define EPSROUND(x,eps) (ceil((x)-0.5+(eps)))
213 #define EPSFRAC(x,eps) ((x)-EPSFLOOR(x,eps))
214 #define EPSISINT(x,eps) (EPSFRAC(x,eps) <= (eps))
215 
216 
217 #ifndef SQR
218 #define SQR(x) ((x)*(x))
219 #define SQRT(x) (sqrt(x))
220 #endif
221 
222 /* platform-dependent specification of the log1p, which is numerically more stable around x = 0.0 */
223 #ifndef LOG1P
224 #if defined(_WIN32) || defined(_WIN64)
225 #define LOG1P(x) (log(1.0+x))
226 #else
227 #define LOG1P(x) (log1p(x))
228 #endif
229 #endif
230 
231 #ifndef LOG2
232 #if defined(_MSC_VER) && (_MSC_VER < 1800)
233 #define LOG2(x) (log(x) / log(2.0))
234 #else
235 #define LOG2(x) log2(x)
236 #endif
237 #endif
238 
239 #ifndef ABS
240 #define ABS(x) ((x) >= 0 ? (x) : -(x))
241 #endif
242 
243 #ifndef MAX
244 #define MAX(x, y) ((x) >= (y) ? (x) : (y)) /**< returns maximum of x and y */
245 #endif
246 
247 #ifndef MIN
248 #define MIN(x, y) ((x) <= (y) ? (x) : (y)) /**< returns minimum of x and y */
249 #endif
250 
251 #ifndef MAX3
252 #define MAX3(x, y, z) ((x) >= (y) ? MAX(x, z) : MAX(y, z)) /**< returns maximum of x, y, and z */
253 #endif
254 
255 #ifndef MIN3
256 #define MIN3(x, y, z) ((x) <= (y) ? MIN(x, z) : MIN(y, z)) /**< returns minimum of x, y, and z */
257 #endif
258 
259 #ifndef COPYSIGN
260 #if defined(_MSC_VER) && (_MSC_VER < 1800)
261 #define COPYSIGN _copysign
262 #else
263 #define COPYSIGN copysign
264 #endif
265 #endif
266 
267 /*
268  * Pointers
269  */
270 
271 #ifndef NULL
272 #define NULL ((void*)0) /**< zero pointer */
273 #endif
274 
275 #ifndef RESTRICT
276 #if defined(_MSC_VER)
277 #define RESTRICT __restrict
278 #else
279 #ifdef __cplusplus
280 #define RESTRICT __restrict__
281 #elif __STDC_VERSION__ >= 199901L
282 #define RESTRICT restrict
283 #else
284 #define RESTRICT
285 #endif
286 #endif
287 #endif
288 
289 /*
290  * Strings
291  */
292 
293 #define SCIP_MAXSTRLEN 1024 /**< maximum string length in SCIP */
294 
295 /*
296  * Memory settings
297  */
298 
299 /* we use SIZE_MAX / 2 to detect negative sizes which got a very large value when casting to size_t */
300 #define SCIP_MAXMEMSIZE (SIZE_MAX/2) /**< maximum size of allocated memory (array) */
301 
302 #define SCIP_HASHSIZE_PARAMS 2048 /**< size of hash table in parameter name tables */
303 #define SCIP_HASHSIZE_NAMES 500 /**< size of hash table in name tables */
304 #define SCIP_HASHSIZE_CUTPOOLS 500 /**< size of hash table in cut pools */
305 #define SCIP_HASHSIZE_CLIQUES 500 /**< size of hash table in clique tables */
306 #define SCIP_HASHSIZE_NAMES_SMALL 100 /**< size of hash table in name tables for small problems */
307 #define SCIP_HASHSIZE_CUTPOOLS_SMALL 100 /**< size of hash table in cut pools for small problems */
308 #define SCIP_HASHSIZE_CLIQUES_SMALL 100 /**< size of hash table in clique tables for small problems */
309 #define SCIP_HASHSIZE_VBC 500 /**< size of hash map for node -> nodenum mapping used for VBC output */
310 
311 #define SCIP_DEFAULT_MEM_ARRAYGROWFAC 1.2 /**< memory growing factor for dynamically allocated arrays */
312 #define SCIP_DEFAULT_MEM_ARRAYGROWINIT 4 /**< initial size of dynamically allocated arrays */
313 
314 #define SCIP_MEM_NOLIMIT (SCIP_Longint)(SCIP_LONGINT_MAX >> 20)/**< initial size of dynamically allocated arrays */
315 
316 /*
317  * Tree settings
318  */
319 
320 #define SCIP_MAXTREEDEPTH 65534 /**< maximal allowed depth of the branch-and-bound tree */
321 
322 /*
323  * Probing scoring settings
324  */
325 
326 #define SCIP_PROBINGSCORE_PENALTYRATIO 2 /**< ratio for penalizing too small fractionalities in diving heuristics.
327  * if the fractional part of a variable is smaller than a given threshold
328  * the corresponding score gets penalized. due to numerical troubles
329  * we will flip a coin whenever SCIPisEQ(scip, fractionality, threshold)
330  * evaluates to true. this parameter defines the chance that this results
331  * in penalizing the score, i.e., there is 1:2 chance for penalizing.
332  */
333 
334 /*
335  * Global debugging settings
336  */
337 
338 /*#define DEBUG*/
339 
340 
341 /*
342  * Defines for handling SCIP return codes
343  */
344 
345 /** this macro is used to stop SCIP in debug mode such that errors can be debugged;
346  *
347  * @note In optimized mode this macro has no effect. That means, in case of an error it has to be ensured that code
348  * terminates with an error code or continues safely.
349  */
350 #define SCIPABORT() assert(FALSE) /*lint --e{527} */
351 
352 #define SCIP_CALL_ABORT_QUIET(x) do { if( (x) != SCIP_OKAY ) SCIPABORT(); } while( FALSE )
353 #define SCIP_CALL_QUIET(x) do { SCIP_RETCODE _restat_; if( (_restat_ = (x)) != SCIP_OKAY ) return _restat_; } while( FALSE )
354 #define SCIP_ALLOC_ABORT_QUIET(x) do { if( NULL == (x) ) SCIPABORT(); } while( FALSE )
355 #define SCIP_ALLOC_QUIET(x) do { if( NULL == (x) ) return SCIP_NOMEMORY; } while( FALSE )
357 #define SCIP_CALL_ABORT(x) do \
358  { \
359  SCIP_RETCODE _restat_; /*lint -e{506,774}*/ \
360  if( (_restat_ = (x)) != SCIP_OKAY ) \
361  { \
362  SCIPerrorMessage("Error <%d> in function call\n", _restat_); \
363  SCIPABORT(); \
364  } \
365  } \
366  while( FALSE )
367 
368 #define SCIP_ALLOC_ABORT(x) do \
369  { \
370  if( NULL == (x) ) \
371  { \
372  SCIPerrorMessage("No memory in function call\n"); \
373  SCIPABORT(); \
374  } \
375  } \
376  while( FALSE )
377 
378 #define SCIP_CALL(x) do \
379  { \
380  SCIP_RETCODE _restat_; /*lint -e{506,774}*/ \
381  if( (_restat_ = (x)) != SCIP_OKAY ) \
382  { \
383  SCIPerrorMessage("Error <%d> in function call\n", _restat_); \
384  return _restat_; \
385  } \
386  } \
387  while( FALSE )
388 
389 #define SCIP_ALLOC(x) do \
390  { \
391  if( NULL == (x) ) \
392  { \
393  SCIPerrorMessage("No memory in function call\n"); \
394  return SCIP_NOMEMORY; \
395  } \
396  } \
397  while( FALSE )
398 
399 #define SCIP_CALL_TERMINATE(retcode, x, TERM) do \
400  { \
401  if( ((retcode) = (x)) != SCIP_OKAY ) \
402  { \
403  SCIPerrorMessage("Error <%d> in function call\n", retcode); \
404  goto TERM; \
405  } \
406  } \
407  while( FALSE )
408 
409 #define SCIP_ALLOC_TERMINATE(retcode, x, TERM) do \
410  { \
411  if( NULL == (x) ) \
412  { \
413  SCIPerrorMessage("No memory in function call\n"); \
414  retcode = SCIP_NOMEMORY; \
415  goto TERM; \
416  } \
417  } \
418  while( FALSE )
419 
420 #define SCIP_CALL_FINALLY(x, y) do \
421  { \
422  SCIP_RETCODE _restat_; \
423  if( (_restat_ = (x)) != SCIP_OKAY ) \
424  { \
425  SCIPerrorMessage("Error <%d> in function call\n", _restat_); \
426  (y); \
427  return _restat_; \
428  } \
429  } \
430  while( FALSE )
431 
432 #define SCIP_UNUSED(x) ((void) (x))
433 
434 /*
435  * Define to mark deprecated API functions
436  */
437 
438 #ifndef SCIP_DEPRECATED
439 #if defined(_MSC_VER)
440 # define SCIP_DEPRECATED __declspec(deprecated)
441 #elif defined(__GNUC__)
442 # define SCIP_DEPRECATED __attribute__ ((deprecated))
443 #else
444 # define SCIP_DEPRECATED
445 #endif
446 #endif
447 
448 #ifdef __cplusplus
449 }
450 #endif
451 
452 #endif
type definitions for return codes for SCIP methods
public methods for message output
type definitions for message output methods