Scippy

    SCIP

    Solving Constraint Integer Programs

    sepastoreexact.c
    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 sepastoreexact.c
    26 * @brief internal methods for storing separated exact cuts
    27 * @author Leon Eifler
    28 */
    29
    30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    31
    32
    33#include <assert.h>
    34
    35#include "scip/def.h"
    36#include "scip/cons.h"
    37#include "scip/cuts.h"
    38#include "scip/debug.h"
    39#include "scip/event.h"
    40#include "scip/lp.h"
    41#include "scip/lpexact.h"
    42#include "scip/misc.h"
    43#include "scip/rational.h"
    44#include "scip/reopt.h"
    45#include "scip/sepa.h"
    46#include "scip/sepastoreexact.h"
    47#include "scip/set.h"
    48#include "scip/stat.h"
    49#include "scip/struct_lpexact.h"
    51#include "scip/tree.h"
    52#include "scip/var.h"
    53
    54/** resizes cuts and score arrays to be able to store at least num entries */
    55static
    57 SCIP_SEPASTOREEXACT* sepastoreexact, /**< separation storage */
    58 SCIP_SET* set, /**< global SCIP settings */
    59 int num /**< minimal number of slots in array */
    60 )
    61{
    62 assert(sepastoreexact != NULL);
    63 assert(set != NULL);
    64
    65 if( num > sepastoreexact->cutssize )
    66 {
    67 int newsize;
    68
    69 newsize = SCIPsetCalcMemGrowSize(set, num);
    70 SCIP_ALLOC( BMSreallocMemoryArray(&sepastoreexact->cuts, newsize) );
    71 sepastoreexact->cutssize = newsize;
    72 }
    73 assert(num <= sepastoreexact->cutssize);
    74
    75 return SCIP_OKAY;
    76}
    77
    78/** creates separation storage */
    80 SCIP_SEPASTOREEXACT** sepastoreexact, /**< pointer to store separation storage */
    81 SCIP_SET* set /**< global SCIP settings */
    82 )
    83{
    84 if( !set->exact_enable )
    85 return SCIP_OKAY;
    86
    87 assert(sepastoreexact != NULL);
    88
    89 SCIP_ALLOC( BMSallocMemory(sepastoreexact) );
    90
    91 (*sepastoreexact)->cuts = NULL;
    92 (*sepastoreexact)->cutssize = 0;
    93 (*sepastoreexact)->ncuts = 0;
    94 (*sepastoreexact)->ncutsfound = 0;
    95 (*sepastoreexact)->ncutsfoundround = 0;
    96 (*sepastoreexact)->ncutsapplied = 0;
    97
    98 (*sepastoreexact)->initiallp = FALSE;
    99
    100 return SCIP_OKAY;
    101}
    102
    103/** frees separation storage */
    105 SCIP_SEPASTOREEXACT** sepastoreexact /**< pointer to store separation storage */
    106 )
    107{
    108 assert(sepastoreexact != NULL);
    109 assert(*sepastoreexact != NULL);
    110 assert((*sepastoreexact)->ncuts == 0);
    111
    112 BMSfreeMemoryArrayNull(&(*sepastoreexact)->cuts);
    113 BMSfreeMemory(sepastoreexact);
    114
    115 return SCIP_OKAY;
    116}
    117
    118#ifdef SCIP_DISABLED_CODE
    119/** informs separation storage that the setup of the initial LP starts now */
    120void SCIPsepastoreExactStartInitialLP(
    121 SCIP_SEPASTOREEXACT* sepastoreexact /**< separation storage */
    122 )
    123{
    124 assert(sepastoreexact != NULL);
    125 assert(!sepastoreexact->initiallp);
    126 assert(sepastoreexact->ncuts == 0);
    127
    128 sepastoreexact->initiallp = TRUE;
    129}
    130
    131/** informs separation storage that the setup of the initial LP is now finished */
    132void SCIPsepastoreExactEndInitialLP(
    133 SCIP_SEPASTOREEXACT* sepastoreexact /**< separation storage */
    134 )
    135{
    136 assert(sepastoreexact != NULL);
    137 assert(sepastoreexact->initiallp);
    138 assert(sepastoreexact->ncuts == 0);
    139
    140 sepastoreexact->initiallp = FALSE;
    141}
    142#endif
    143
    144/** adds cut to separation storage and captures it */
    146 SCIP_SEPASTOREEXACT* sepastoreexact, /**< separation storage */
    147 SCIP_SET* set, /**< global SCIP settings */
    148 SCIP_EVENTQUEUE* eventqueue, /**< event queue */
    149 SCIP_ROWEXACT* cut /**< separated cut */
    150 )
    151{
    152 int pos;
    153
    154 assert(sepastoreexact != NULL);
    155 assert(set != NULL);
    156 assert(cut != NULL);
    158 assert(eventqueue != NULL);
    159
    160 /* debug: check cut for feasibility; note that this just checks for fp feasibility and could be extended */
    161 SCIP_CALL( SCIPdebugCheckRow(set, cut->fprow) ); /*lint !e506 !e774*/
    162
    163 /* update statistics of total number of found cuts */
    164 if( !sepastoreexact->initiallp )
    165 {
    166 sepastoreexact->ncutsfound++;
    167 sepastoreexact->ncutsfoundround++;
    168 }
    169
    170 /* get enough memory to store the cut */
    171 SCIP_CALL( sepastoreExactEnsureCutsMem(sepastoreexact, set, sepastoreexact->ncuts+1) );
    172 assert(sepastoreexact->ncuts < sepastoreexact->cutssize);
    173
    174 SCIPsetDebugMsg(set, "adding cut <%s> to exact separation storage of size %d (len=%d)\n",
    175 SCIProwGetName(cut->fprow), sepastoreexact->ncuts, SCIProwGetNNonz(cut->fprow));
    176 /*SCIP_CALL( SCIPprintRow(set->scip, cut, NULL) );*/
    177
    178 /* capture the cut */
    180
    181 pos = sepastoreexact->ncuts;
    182
    183 sepastoreexact->cuts[pos] = cut;
    184 sepastoreexact->ncuts++;
    185
    186 return SCIP_OKAY;
    187}
    188
    189/** clears the separation storage without adding the cuts to the LP */
    191 SCIP_SEPASTOREEXACT* sepastoreexact, /**< separation storage */
    192 BMS_BLKMEM* blkmem, /**< block memory */
    193 SCIP_SET* set, /**< global SCIP settings */
    194 SCIP_LPEXACT* lp /**< LP data */
    195 )
    196{
    197 int c;
    198
    199 if( !set->exact_enable )
    200 return SCIP_OKAY;
    201
    202 assert(sepastoreexact != NULL);
    203
    204 SCIPsetDebugMsg(set, "clearing %d cuts\n", sepastoreexact->ncuts);
    205
    206 /* release cuts */
    207 for( c = 0; c < sepastoreexact->ncuts; ++c )
    208 {
    209 SCIP_CALL( SCIProwExactRelease(&sepastoreexact->cuts[c], blkmem, set, lp) );
    210 }
    211
    212 /* reset counters */
    213 sepastoreexact->ncuts = 0;
    214 sepastoreexact->ncutsfoundround = 0;
    215
    216 /* if we have just finished the initial LP construction, free the (potentially large) cuts array */
    217 if( sepastoreexact->initiallp )
    218 {
    219 BMSfreeMemoryArrayNull(&sepastoreexact->cuts);
    220 sepastoreexact->cutssize = 0;
    221 }
    222
    223 return SCIP_OKAY;
    224}
    225
    226
    227/** get cuts in the separation storage */
    229 SCIP_SEPASTOREEXACT* sepastoreexact /**< separation storage */
    230 )
    231{
    232 assert(sepastoreexact != NULL);
    233
    234 return sepastoreexact->cuts;
    235}
    236
    237/** get number of cuts in the separation storage */
    239 SCIP_SEPASTOREEXACT* sepastoreexact /**< separation storage */
    240 )
    241{
    242 assert(sepastoreexact != NULL);
    243
    244 return sepastoreexact->ncuts;
    245}
    246
    247/** get total number of cuts found so far */
    249 SCIP_SEPASTOREEXACT* sepastoreexact /**< separation storage */
    250 )
    251{
    252 assert(sepastoreexact != NULL);
    253
    254 return sepastoreexact->ncutsfound;
    255}
    256
    257/** get number of cuts found so far in current separation round */
    259 SCIP_SEPASTOREEXACT* sepastoreexact /**< separation storage */
    260 )
    261{
    262 assert(sepastoreexact != NULL);
    263
    264 return sepastoreexact->ncutsfoundround;
    265}
    266
    267/** get total number of cuts applied to the LPs */
    269 SCIP_SEPASTOREEXACT* sepastoreexact /**< separation storage */
    270 )
    271{
    272 assert(sepastoreexact != NULL);
    273
    274 return sepastoreexact->ncutsapplied;
    275}
    internal methods for constraints and constraint handlers
    methods for the aggregation rows
    methods for debugging
    #define SCIPdebugCheckRow(set, row)
    Definition: debug.h:297
    common defines and data types used in all packages of SCIP
    #define NULL
    Definition: def.h:248
    #define SCIP_ALLOC(x)
    Definition: def.h:366
    #define TRUE
    Definition: def.h:93
    #define FALSE
    Definition: def.h:94
    #define SCIP_CALL(x)
    Definition: def.h:355
    internal methods for managing events
    SCIP_Bool SCIPrationalIsInfinity(SCIP_RATIONAL *rational)
    Definition: rational.cpp:1660
    SCIP_Bool SCIPrationalIsNegInfinity(SCIP_RATIONAL *rational)
    Definition: rational.cpp:1670
    int SCIProwGetNNonz(SCIP_ROW *row)
    Definition: lp.c:17607
    const char * SCIProwGetName(SCIP_ROW *row)
    Definition: lp.c:17745
    internal methods for LP management
    SCIP_RATIONAL * SCIProwExactGetRhs(SCIP_ROWEXACT *row)
    Definition: lpexact.c:6266
    void SCIProwExactCapture(SCIP_ROWEXACT *row)
    Definition: lpexact.c:4940
    SCIP_RETCODE SCIProwExactRelease(SCIP_ROWEXACT **row, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LPEXACT *lpexact)
    Definition: lpexact.c:5583
    SCIP_RATIONAL * SCIProwExactGetLhs(SCIP_ROWEXACT *row)
    Definition: lpexact.c:6255
    internal methods for exact LP management
    #define BMSfreeMemory(ptr)
    Definition: memory.h:145
    #define BMSreallocMemoryArray(ptr, num)
    Definition: memory.h:127
    struct BMS_BlkMem BMS_BLKMEM
    Definition: memory.h:437
    #define BMSfreeMemoryArrayNull(ptr)
    Definition: memory.h:148
    #define BMSallocMemory(ptr)
    Definition: memory.h:118
    internal miscellaneous methods
    wrapper for rational number arithmetic
    data structures and methods for collecting reoptimization information
    internal methods for separators
    int SCIPsepastoreExactGetNCutsFoundRound(SCIP_SEPASTOREEXACT *sepastoreexact)
    SCIP_RETCODE SCIPsepastoreExactFree(SCIP_SEPASTOREEXACT **sepastoreexact)
    int SCIPsepastoreExactGetNCuts(SCIP_SEPASTOREEXACT *sepastoreexact)
    static SCIP_RETCODE sepastoreExactEnsureCutsMem(SCIP_SEPASTOREEXACT *sepastoreexact, SCIP_SET *set, int num)
    SCIP_RETCODE SCIPsepastoreExactClearCuts(SCIP_SEPASTOREEXACT *sepastoreexact, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LPEXACT *lp)
    int SCIPsepastoreExactGetNCutsFound(SCIP_SEPASTOREEXACT *sepastoreexact)
    int SCIPsepastoreExactGetNCutsApplied(SCIP_SEPASTOREEXACT *sepastoreexact)
    SCIP_ROWEXACT ** SCIPsepastoreExactGetCuts(SCIP_SEPASTOREEXACT *sepastoreexact)
    SCIP_RETCODE SCIPsepastoreExactCreate(SCIP_SEPASTOREEXACT **sepastoreexact, SCIP_SET *set)
    SCIP_RETCODE SCIPsepastoreExactAddCut(SCIP_SEPASTOREEXACT *sepastoreexact, SCIP_SET *set, SCIP_EVENTQUEUE *eventqueue, SCIP_ROWEXACT *cut)
    internal methods for storing separated exact cuts
    int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
    Definition: set.c:6080
    internal methods for global SCIP settings
    #define SCIPsetDebugMsg
    Definition: set.h:1811
    internal methods for problem statistics
    SCIP_ROW * fprow
    SCIP_ROWEXACT ** cuts
    data structures for exact LP management
    datastructures for storing conflicts
    Definition: heur_padm.c:135
    internal methods for branch and bound tree
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63
    internal methods for problem variables