Scippy

    SCIP

    Solving Constraint Integer Programs

    objtable.cpp
    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 objtable.cpp
    26 * @brief C++ wrapper for statistics tables
    27 * @author Tristan Gally
    28 */
    29
    30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    31
    32#include <cassert>
    33
    34#include "objtable.h"
    35
    36
    37
    38
    39/*
    40 * Data structures
    41 */
    42
    43/** display table data */
    44struct SCIP_TableData
    45{
    46 scip::ObjTable* objtable; /**< display statistics table object */
    47 SCIP_Bool deleteobject; /**< should the statistics table object be deleted when statistics table is freed? */
    48};
    49
    50
    51namespace scip
    52{
    53
    54SCIP_DECL_TABLEOUTPUT(ObjTable::scip_output)
    55{
    56 SCIP_DATATREE* datatree;
    57
    58 SCIP_CALL( SCIPcreateDatatree(scip, &datatree, -1) );
    59 SCIP_CALL( scip_collect(scip, table, datatree) );
    60
    61 SCIP_CALL( SCIPprintDatatreeAsTable(scip, datatree, file, scip_name_, scip_name_) );
    62
    63 SCIPfreeDatatree(scip, &datatree);
    64
    65 return SCIP_OKAY;
    66}
    67
    68}
    69
    70
    71/*
    72 * Callback methods of statistics table
    73 */
    74
    75extern "C"
    76{
    77
    78/** copy method for statistics table plugins (called when SCIP copies plugins) */
    79static
    81{ /*lint --e{715}*/
    82 SCIP_TABLEDATA* tabledata;
    83
    84 assert(scip != NULL);
    85
    86 tabledata = SCIPtableGetData(table);
    87 assert(tabledata != NULL);
    88 assert(tabledata->objtable != NULL);
    89 assert(tabledata->objtable->scip_ != scip);
    90
    91 if( tabledata->objtable->iscloneable() )
    92 {
    93 scip::ObjTable* newobjtable;
    94 newobjtable = dynamic_cast<scip::ObjTable*> (tabledata->objtable->clone(scip));
    95
    96 /* call include method of display column object */
    97 SCIP_CALL( SCIPincludeObjTable(scip, newobjtable, TRUE) );
    98 }
    99
    100 return SCIP_OKAY;
    101}
    102
    103/** destructor of statistics table to free user data (called when SCIP is exiting) */
    104static
    106{ /*lint --e{715}*/
    107 SCIP_TABLEDATA* tabledata;
    108
    109 tabledata = SCIPtableGetData(table);
    110 assert(tabledata != NULL);
    111 assert(tabledata->objtable != NULL);
    112 assert(tabledata->objtable->scip_ == scip);
    113
    114 /* call virtual method of statistics table object */
    115 SCIP_CALL( tabledata->objtable->scip_free(scip, table) );
    116
    117 /* free statistics table object */
    118 if( tabledata->deleteobject )
    119 delete tabledata->objtable;
    120
    121 /* free statistics table data */
    122 delete tabledata;
    123 SCIPtableSetData(table, NULL); /*lint !e64*/
    124
    125 return SCIP_OKAY;
    126}
    127
    128
    129/** initialization method of statistics table (called after problem was transformed) */
    130static
    132{ /*lint --e{715}*/
    133 SCIP_TABLEDATA* tabledata;
    134
    135 tabledata = SCIPtableGetData(table);
    136 assert(tabledata != NULL);
    137 assert(tabledata->objtable != NULL);
    138 assert(tabledata->objtable->scip_ == scip);
    139
    140 /* call virtual method of statistics table object */
    141 SCIP_CALL( tabledata->objtable->scip_init(scip, table) );
    142
    143 return SCIP_OKAY;
    144}
    145
    146
    147/** deinitialization method of statistics table (called before transformed problem is freed) */
    148static
    150{ /*lint --e{715}*/
    151 SCIP_TABLEDATA* tabledata;
    152
    153 tabledata = SCIPtableGetData(table);
    154 assert(tabledata != NULL);
    155 assert(tabledata->objtable != NULL);
    156
    157 /* call virtual method of statistics table object */
    158 SCIP_CALL( tabledata->objtable->scip_exit(scip, table) );
    159
    160 return SCIP_OKAY;
    161}
    162
    163
    164/** solving process initialization method of statistics table (called when branch and bound process is about to begin) */
    165static
    167{ /*lint --e{715}*/
    168 SCIP_TABLEDATA* tabledata;
    169
    170 tabledata = SCIPtableGetData(table);
    171 assert(tabledata != NULL);
    172 assert(tabledata->objtable != NULL);
    173
    174 /* call virtual method of statistics table object */
    175 SCIP_CALL( tabledata->objtable->scip_initsol(scip, table) );
    176
    177 return SCIP_OKAY;
    178}
    179
    180
    181/** solving process deinitialization method of statistics table (called before branch and bound process data is freed) */
    182static
    184{ /*lint --e{715}*/
    185 SCIP_TABLEDATA* tabledata;
    186
    187 tabledata = SCIPtableGetData(table);
    188 assert(tabledata != NULL);
    189 assert(tabledata->objtable != NULL);
    190
    191 /* call virtual method of statistics table object */
    192 SCIP_CALL( tabledata->objtable->scip_exitsol(scip, table) );
    193
    194 return SCIP_OKAY;
    195}
    196
    197
    198/** output method of statistics table to output file stream 'file' */
    199static
    201{ /*lint --e{715}*/
    202 SCIP_TABLEDATA* tabledata;
    203
    204 tabledata = SCIPtableGetData(table);
    205 assert(tabledata != NULL);
    206 assert(tabledata->objtable != NULL);
    207
    208 /* call virtual method of statistics table object */
    209 SCIP_CALL( tabledata->objtable->scip_output(scip, table, file) );
    210
    211 return SCIP_OKAY;
    212}
    213
    214/** data collection method */
    215static
    217{ /*lint --e{715}*/
    218 SCIP_TABLEDATA* tabledata;
    219
    220 tabledata = SCIPtableGetData(table);
    221 assert(tabledata != NULL);
    222 assert(tabledata->objtable != NULL);
    223
    224 /* call virtual method of statistics table object */
    225 SCIP_CALL( tabledata->objtable->scip_collect(scip, table, datatree) );
    226
    227 return SCIP_OKAY;
    228}
    229
    230}
    231
    232
    233
    234/*
    235 * statistics table specific interface methods
    236 */
    237
    238/** creates the statistics table for the given statistics table object and includes it in SCIP */
    240 SCIP* scip, /**< SCIP data structure */
    241 scip::ObjTable* objtable, /**< statistics table object */
    242 SCIP_Bool deleteobject /**< should the statistics table object be deleted when statistics table is freed? */
    243 )
    244{
    245 SCIP_TABLEDATA* tabledata;
    246
    247 assert(scip != NULL);
    248 assert(objtable != NULL);
    249
    250 /* create statistics table data */
    251 tabledata = new SCIP_TABLEDATA;
    252 tabledata->objtable = objtable;
    253 tabledata->deleteobject = deleteobject;
    254
    255 /* include statistics table */
    257 tableCopyObj, tableFreeObj, tableInitObj, tableExitObj, tableInitsolObj,
    258 tableExitsolObj, tableOutputObj, tableCollectObj, tabledata, objtable->scip_position_, objtable->scip_earlieststage_) ); /*lint !e429*/
    259
    260 return SCIP_OKAY; /*lint !e429*/
    261}
    262
    263/** returns the statistics table object of the given name, or 0 if not existing */
    265 SCIP* scip, /**< SCIP data structure */
    266 const char* name /**< name of statistics table */
    267 )
    268{
    269 SCIP_TABLE* table;
    270 SCIP_TABLEDATA* tabledata;
    271
    272 table = SCIPfindTable(scip, name);
    273 if( table == NULL )
    274 return 0;
    275
    276 tabledata = SCIPtableGetData(table);
    277 assert(tabledata != NULL);
    278
    279 return tabledata->objtable;
    280}
    281
    282/** returns the statistics table object for the given statistics table */
    284 SCIP* scip, /**< SCIP data structure */
    285 SCIP_TABLE* table /**< statistics table */
    286 )
    287{
    288 SCIP_TABLEDATA* tabledata;
    289
    290 assert(scip != NULL);
    291 tabledata = SCIPtableGetData(table);
    292 assert(tabledata != NULL);
    293
    294 return tabledata->objtable;
    295}
    C++ wrapper for statistics tables.
    Definition: objtable.h:54
    char * scip_desc_
    Definition: objtable.h:65
    char * scip_name_
    Definition: objtable.h:62
    const int scip_position_
    Definition: objtable.h:68
    SCIP_STAGE scip_earlieststage_
    Definition: objtable.h:71
    #define NULL
    Definition: def.h:248
    #define SCIP_Bool
    Definition: def.h:91
    #define TRUE
    Definition: def.h:93
    #define SCIP_CALL(x)
    Definition: def.h:355
    SCIP_RETCODE SCIPprintDatatreeAsTable(SCIP *scip, SCIP_DATATREE *datatree, FILE *file, const char *sectionname, const char *tablename)
    void SCIPfreeDatatree(SCIP *scip, SCIP_DATATREE **datatree)
    SCIP_RETCODE SCIPcreateDatatree(SCIP *scip, SCIP_DATATREE **datatree, int capacity)
    Definition: scip_datatree.c:46
    SCIP_TABLEDATA * SCIPtableGetData(SCIP_TABLE *table)
    Definition: table.c:326
    SCIP_TABLE * SCIPfindTable(SCIP *scip, const char *name)
    Definition: scip_table.c:101
    SCIP_RETCODE SCIPincludeTable(SCIP *scip, const char *name, const char *desc, SCIP_Bool active, SCIP_DECL_TABLECOPY((*tablecopy)), SCIP_DECL_TABLEFREE((*tablefree)), SCIP_DECL_TABLEINIT((*tableinit)), SCIP_DECL_TABLEEXIT((*tableexit)), SCIP_DECL_TABLEINITSOL((*tableinitsol)), SCIP_DECL_TABLEEXITSOL((*tableexitsol)), SCIP_DECL_TABLEOUTPUT((*tableoutput)), SCIP_DECL_TABLECOLLECT((*tablecollect)), SCIP_TABLEDATA *tabledata, int position, SCIP_STAGE earlieststage)
    Definition: scip_table.c:62
    void SCIPtableSetData(SCIP_TABLE *table, SCIP_TABLEDATA *tabledata)
    Definition: table.c:336
    SCIP_DECL_TABLEOUTPUT(ObjTable::scip_output)
    Definition: objtable.cpp:54
    static SCIP_DECL_TABLEEXITSOL(tableExitsolObj)
    Definition: objtable.cpp:183
    static SCIP_DECL_TABLEINIT(tableInitObj)
    Definition: objtable.cpp:131
    static SCIP_DECL_TABLECOPY(tableCopyObj)
    Definition: objtable.cpp:80
    scip::ObjTable * SCIPgetObjTable(SCIP *scip, SCIP_TABLE *table)
    Definition: objtable.cpp:283
    SCIP_RETCODE SCIPincludeObjTable(SCIP *scip, scip::ObjTable *objtable, SCIP_Bool deleteobject)
    Definition: objtable.cpp:239
    static SCIP_DECL_TABLEEXIT(tableExitObj)
    Definition: objtable.cpp:149
    static SCIP_DECL_TABLEOUTPUT(tableOutputObj)
    Definition: objtable.cpp:200
    scip::ObjTable * SCIPfindObjTable(SCIP *scip, const char *name)
    Definition: objtable.cpp:264
    static SCIP_DECL_TABLECOLLECT(tableCollectObj)
    Definition: objtable.cpp:216
    static SCIP_DECL_TABLEFREE(tableFreeObj)
    Definition: objtable.cpp:105
    static SCIP_DECL_TABLEINITSOL(tableInitsolObj)
    Definition: objtable.cpp:166
    C++ wrapper for statistics tables.
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63
    struct SCIP_TableData SCIP_TABLEDATA
    Definition: type_table.h:60