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