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