Scippy

SCIP

Solving Constraint Integer Programs

table.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 table.c
26 * @ingroup OTHER_CFILES
27 * @brief methods and datastructures for displaying statistics tables
28 * @author Tristan Gally
29 * @author Mohammed Ghannam
30 */
31
32/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
33
34#include <stdio.h>
35#include <assert.h>
36#include <string.h>
37
38#include "scip/def.h"
40#include "scip/set.h"
41#include "scip/stat.h"
42#include "scip/scip.h"
43#include "scip/datatree.h"
44#include "scip/table.h"
45#include "scip/struct_table.h"
46
47
48/*
49 * statistics table methods
50 */
51
52/** copies the given statistics table to a new scip */
54 SCIP_TABLE* table, /**< statistics table */
55 SCIP_SET* set /**< SCIP_SET of SCIP to copy to */
56 )
57{
58 assert(table != NULL);
59 assert(set != NULL);
60 assert(set->scip != NULL);
61
62 if( table->tablecopy != NULL )
63 {
64 SCIPsetDebugMsg(set, "including statistics table %s in subscip %p\n", SCIPtableGetName(table), (void*)set->scip);
65 SCIP_CALL( table->tablecopy(set->scip, table) );
66 }
67 return SCIP_OKAY;
68}
69
70/** internal method for creating a statistics table */
71static
73 SCIP_TABLE** table, /**< pointer to store statistics table */
74 SCIP_SET* set, /**< global SCIP settings */
75 SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
76 BMS_BLKMEM* blkmem, /**< block memory for parameter settings */
77 const char* name, /**< name of statistics table */
78 const char* desc, /**< description of statistics table */
79 SCIP_Bool active, /**< should the table be activated by default? */
80 SCIP_DECL_TABLECOPY ((*tablecopy)), /**< copy method of statistics table or NULL if you don't want to copy your plugin into sub-SCIPs */
81 SCIP_DECL_TABLEFREE ((*tablefree)), /**< destructor of statistics table */
82 SCIP_DECL_TABLEINIT ((*tableinit)), /**< initialize statistics table */
83 SCIP_DECL_TABLEEXIT ((*tableexit)), /**< deinitialize statistics table */
84 SCIP_DECL_TABLEINITSOL ((*tableinitsol)), /**< solving process initialization method of statistics table */
85 SCIP_DECL_TABLEEXITSOL ((*tableexitsol)), /**< solving process deinitialization method of statistics table */
86 SCIP_DECL_TABLEOUTPUT ((*tableoutput)), /**< output method */
87 SCIP_DECL_TABLECOLLECT((*tablecollect)), /**< data collection method */
88 SCIP_TABLEDATA* tabledata, /**< display statistics table */
89 int position, /**< position of statistics table */
90 SCIP_STAGE earlieststage /**< output of the statistics table is only printed from this stage onwards */
91 )
92{
94 char paramdesc[SCIP_MAXSTRLEN];
95
96 assert(table != NULL);
97 assert(name != NULL);
98 assert(desc != NULL);
99 assert(tablecollect != NULL || tableoutput != NULL);
100
101 SCIP_ALLOC( BMSallocMemory(table) );
102 BMSclearMemory(*table);
103
104 SCIP_ALLOC( BMSduplicateMemoryArray(&(*table)->name, name, strlen(name)+1) );
105 SCIP_ALLOC( BMSduplicateMemoryArray(&(*table)->desc, desc, strlen(desc)+1) );
106 (*table)->tablecopy = tablecopy;
107 (*table)->tablefree = tablefree;
108 (*table)->tableinit = tableinit;
109 (*table)->tableexit = tableexit;
110 (*table)->tableinitsol = tableinitsol;
111 (*table)->tableexitsol = tableexitsol;
112 (*table)->tableoutput = tableoutput;
113 (*table)->tablecollect = tablecollect;
114 (*table)->tabledata = tabledata;
115 (*table)->position = position;
116 (*table)->earlieststage = earlieststage;
117 (*table)->initialized = FALSE;
118 (*table)->active = active;
119
120 /* add parameters */
121 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "table/%s/active", name);
122 (void) SCIPsnprintf(paramdesc, SCIP_MAXSTRLEN, "is statistics table <%s> active", name);
123 SCIP_CALL( SCIPsetAddBoolParam(set, messagehdlr, blkmem, paramname, paramdesc,
124 &(*table)->active, FALSE, active, NULL, NULL) );
125
126 return SCIP_OKAY;
127}
128
129/** creates a statistics table */
131 SCIP_TABLE** table, /**< pointer to store statistics table */
132 SCIP_SET* set, /**< global SCIP settings */
133 SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
134 BMS_BLKMEM* blkmem, /**< block memory for parameter settings */
135 const char* name, /**< name of statistics table */
136 const char* desc, /**< description of statistics table */
137 SCIP_Bool active, /**< should the table be activated by default? */
138 SCIP_DECL_TABLECOPY ((*tablecopy)), /**< copy method of statistics table or NULL if you don't want to copy your plugin into sub-SCIPs */
139 SCIP_DECL_TABLEFREE ((*tablefree)), /**< destructor of statistics table */
140 SCIP_DECL_TABLEINIT ((*tableinit)), /**< initialize statistics table */
141 SCIP_DECL_TABLEEXIT ((*tableexit)), /**< deinitialize statistics table */
142 SCIP_DECL_TABLEINITSOL ((*tableinitsol)), /**< solving process initialization method of statistics table */
143 SCIP_DECL_TABLEEXITSOL ((*tableexitsol)), /**< solving process deinitialization method of statistics table */
144 SCIP_DECL_TABLEOUTPUT ((*tableoutput)), /**< output method */
145 SCIP_DECL_TABLECOLLECT((*tablecollect)), /**< report table data as SCIP_DATATREE */
146 SCIP_TABLEDATA* tabledata, /**< display statistics table */
147 int position, /**< position of statistics table */
148 SCIP_STAGE earlieststage /**< output of the statistics table is only printed from this stage onwards */
149 )
150{
151 assert(table != NULL);
152 assert(name != NULL);
153 assert(desc != NULL);
154 assert(tableoutput != NULL);
155
156 SCIP_CALL_FINALLY( doTableCreate(table, set, messagehdlr, blkmem, name, desc, active, tablecopy, tablefree,
157 tableinit, tableexit, tableinitsol, tableexitsol, tableoutput, tablecollect, tabledata, position, earlieststage),
158 (void) SCIPtableFree(table, set) );
159
160 return SCIP_OKAY;
161}
162
163/** frees memory of statistics table */
165 SCIP_TABLE** table, /**< pointer to statistics table data structure */
166 SCIP_SET* set /**< global SCIP settings */
167 )
168{
169 assert(table != NULL);
170 if( *table == NULL )
171 return SCIP_OKAY;
172 assert(!(*table)->initialized);
173 assert(set != NULL);
174
175 /* call destructor of statistics table */
176 if( (*table)->tablefree != NULL )
177 {
178 SCIP_CALL( (*table)->tablefree(set->scip, *table) );
179 }
180
181 BMSfreeMemoryArrayNull(&(*table)->name);
182 BMSfreeMemoryArrayNull(&(*table)->desc);
183 BMSfreeMemory(table);
184
185 return SCIP_OKAY;
186}
187
188/** initializes statistics table */
190 SCIP_TABLE* table, /**< statistics table */
191 SCIP_SET* set /**< global SCIP settings */
192 )
193{
194 assert(table != NULL);
195 assert(set != NULL);
196
197 if( table->initialized )
198 {
199 SCIPerrorMessage("statistics table <%s> already initialized\n", table->name);
200 return SCIP_INVALIDCALL;
201 }
202
203 if( table->tableinit != NULL )
204 {
205 SCIP_CALL( table->tableinit(set->scip, table) );
206 }
207 table->initialized = TRUE;
208
209 return SCIP_OKAY;
210}
211
212/** deinitializes statistics table */
214 SCIP_TABLE* table, /**< statistics table */
215 SCIP_SET* set /**< global SCIP settings */
216 )
217{
218 assert(table != NULL);
219 assert(set != NULL);
220
221 if( !table->initialized )
222 {
223 SCIPerrorMessage("statistics table <%s> not initialized\n", table->name);
224 return SCIP_INVALIDCALL;
225 }
226
227 if( table->tableexit != NULL )
228 {
229 SCIP_CALL( table->tableexit(set->scip, table) );
230 }
231 table->initialized = FALSE;
232
233 return SCIP_OKAY;
234}
235
236/** informs statistics table that the branch and bound process is being started */
238 SCIP_TABLE* table, /**< statistics table */
239 SCIP_SET* set /**< global SCIP settings */
240 )
241{
242 assert(table != NULL);
243 assert(set != NULL);
244
245 /* call solving process initialization method of statistics table */
246 if( table->tableinitsol != NULL )
247 {
248 SCIP_CALL( table->tableinitsol(set->scip, table) );
249 }
250
251 return SCIP_OKAY;
252}
253
254/** informs statistics table that the branch and bound process data is being freed */
256 SCIP_TABLE* table, /**< statistics table */
257 SCIP_SET* set /**< global SCIP settings */
258 )
259{
260 assert(table != NULL);
261 assert(set != NULL);
262
263 /* call solving process deinitialization method of statistics table */
264 if( table->tableexitsol != NULL )
265 {
266 SCIP_CALL( table->tableexitsol(set->scip, table) );
267 }
268
269 return SCIP_OKAY;
270}
271
272/** output statistics table to screen */
274 SCIP_TABLE* table, /**< statistics table */
275 BMS_BLKMEM* blkmem, /**< block memory */
276 SCIP_SET* set, /**< global SCIP settings */
277 FILE* file /**< output file (or NULL for standard output) */
278 )
279{
280 assert(table != NULL);
281 assert(table->tableoutput != NULL || table->tablecollect != NULL);
282 assert(set != NULL);
283
284 if( table->tableoutput != NULL )
285 {
286 SCIP_CALL( table->tableoutput(set->scip, table, file) );
287 }
288 else
289 {
290 SCIP_DATATREE* datatree;
291
292 SCIP_CALL( SCIPdatatreeCreate(&datatree, blkmem, -1) );
293
294 SCIP_CALL( SCIPtableCollect(table, set, datatree) );
295
296 SCIP_CALL( SCIPprintDatatreeAsTable(set->scip, datatree, file, table->name, table->name) );
297
298 SCIPdatatreeFree(&datatree, blkmem);
299 }
300
301 return SCIP_OKAY;
302}
303
304/** collects statistics table data */
306 SCIP_TABLE* table, /**< statistics table */
307 SCIP_SET* set, /**< global SCIP settings */
308 SCIP_DATATREE* datatree /**< data tree where to add table data */
309 )
310{
311 assert(table != NULL);
312 assert(set != NULL);
313 assert(datatree != NULL);
314
315 SCIP_CALL( SCIPinsertDatatreeString(set->scip, datatree, "description", table->desc) );
316
317 if( table->tablecollect != NULL )
318 {
319 SCIP_CALL( table->tablecollect(set->scip, table, datatree) );
320 }
321
322 return SCIP_OKAY;
323}
324
325/** gets user data of statistics table */
327 SCIP_TABLE* table /**< statistics table */
328 )
329{
330 assert(table != NULL);
331
332 return table->tabledata;
333}
334
335/** sets user data of statistics table; user has to free old data in advance! */
337 SCIP_TABLE* table, /**< statistics table */
338 SCIP_TABLEDATA* tabledata /**< new statistics table user data */
339 )
340{
341 assert(table != NULL);
342
343 table->tabledata = tabledata;
344}
345
346/** gets name of statistics table */
348 SCIP_TABLE* table /**< statistics table */
349 )
350{
351 assert(table != NULL);
352
353 return table->name;
354}
355
356/** gets description of statistics table */
358 SCIP_TABLE* table /**< statistics table */
359 )
360{
361 assert(table != NULL);
362
363 return table->desc;
364}
365
366/** gets position of statistics table */
368 SCIP_TABLE* table /**< statistics table */
369 )
370{
371 assert(table != NULL);
372
373 return table->position;
374}
375
376/** gets earliest stage of statistics table */
378 SCIP_TABLE* table /**< statistics table */
379 )
380{
381 assert(table != NULL);
382
383 return table->earlieststage;
384}
385
386/** is statistics table currently active? */
388 SCIP_TABLE* table /**< statistics table */
389 )
390{
391 assert(table != NULL);
392
393 return table->active;
394}
395
396/** is statistics table initialized? */
398 SCIP_TABLE* table /**< statistics table */
399 )
400{
401 assert(table != NULL);
402
403 return table->initialized;
404}
static GRAPHNODE ** active
SCIP_RETCODE SCIPdatatreeCreate(SCIP_DATATREE **datatree, BMS_BLKMEM *blkmem, int capacity)
Definition: datatree.c:112
void SCIPdatatreeFree(SCIP_DATATREE **datatree, BMS_BLKMEM *blkmem)
Definition: datatree.c:135
internal methods for handling data trees
common defines and data types used in all packages of SCIP
#define NULL
Definition: def.h:248
#define SCIP_MAXSTRLEN
Definition: def.h:269
#define SCIP_Bool
Definition: def.h:91
#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
#define SCIP_CALL_FINALLY(x, y)
Definition: def.h:397
SCIP_RETCODE SCIPprintDatatreeAsTable(SCIP *scip, SCIP_DATATREE *datatree, FILE *file, const char *sectionname, const char *tablename)
SCIP_RETCODE SCIPinsertDatatreeString(SCIP *scip, SCIP_DATATREE *datatree, const char *name, const char *value)
int SCIPtableGetPosition(SCIP_TABLE *table)
Definition: table.c:367
const char * SCIPtableGetDesc(SCIP_TABLE *table)
Definition: table.c:357
SCIP_Bool SCIPtableIsInitialized(SCIP_TABLE *table)
Definition: table.c:397
SCIP_TABLEDATA * SCIPtableGetData(SCIP_TABLE *table)
Definition: table.c:326
const char * SCIPtableGetName(SCIP_TABLE *table)
Definition: table.c:347
void SCIPtableSetData(SCIP_TABLE *table, SCIP_TABLEDATA *tabledata)
Definition: table.c:336
SCIP_STAGE SCIPtableGetEarliestStage(SCIP_TABLE *table)
Definition: table.c:377
SCIP_Bool SCIPtableIsActive(SCIP_TABLE *table)
Definition: table.c:387
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10827
static const char * paramname[]
Definition: lpi_msk.c:5172
memory allocation routines
#define BMSfreeMemory(ptr)
Definition: memory.h:145
#define BMSduplicateMemoryArray(ptr, source, num)
Definition: memory.h:143
#define BMSclearMemory(ptr)
Definition: memory.h:129
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:437
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:148
#define BMSallocMemory(ptr)
Definition: memory.h:118
#define SCIPerrorMessage
Definition: pub_message.h:64
SCIP callable library.
SCIP_RETCODE SCIPsetAddBoolParam(SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: set.c:3207
internal methods for global SCIP settings
#define SCIPsetDebugMsg
Definition: set.h:1811
internal methods for problem statistics
SCIP_TABLEDATA * tabledata
Definition: struct_table.h:58
SCIP_Bool active
Definition: struct_table.h:62
char * name
Definition: struct_table.h:48
SCIP_STAGE earlieststage
Definition: struct_table.h:60
char * desc
Definition: struct_table.h:49
SCIP_Bool initialized
Definition: struct_table.h:61
data structures for displaying statistics tables
Definition: heur_padm.c:135
SCIP_RETCODE SCIPtableCopyInclude(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:53
static SCIP_RETCODE doTableCreate(SCIP_TABLE **table, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, 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: table.c:72
SCIP_RETCODE SCIPtableOutput(SCIP_TABLE *table, BMS_BLKMEM *blkmem, SCIP_SET *set, FILE *file)
Definition: table.c:273
SCIP_RETCODE SCIPtableFree(SCIP_TABLE **table, SCIP_SET *set)
Definition: table.c:164
SCIP_RETCODE SCIPtableExitsol(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:255
SCIP_RETCODE SCIPtableInitsol(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:237
SCIP_RETCODE SCIPtableInit(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:189
SCIP_RETCODE SCIPtableCreate(SCIP_TABLE **table, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, 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: table.c:130
SCIP_RETCODE SCIPtableExit(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:213
SCIP_RETCODE SCIPtableCollect(SCIP_TABLE *table, SCIP_SET *set, SCIP_DATATREE *datatree)
Definition: table.c:305
internal methods for displaying statistics tables
@ SCIP_OKAY
Definition: type_retcode.h:42
@ SCIP_INVALIDCALL
Definition: type_retcode.h:51
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
enum SCIP_Stage SCIP_STAGE
Definition: type_set.h:59
#define SCIP_DECL_TABLEFREE(x)
Definition: type_table.h:77
#define SCIP_DECL_TABLEINITSOL(x)
Definition: type_table.h:104
struct SCIP_TableData SCIP_TABLEDATA
Definition: type_table.h:60
#define SCIP_DECL_TABLEOUTPUT(x)
Definition: type_table.h:124
#define SCIP_DECL_TABLEINIT(x)
Definition: type_table.h:85
#define SCIP_DECL_TABLEEXITSOL(x)
Definition: type_table.h:115
#define SCIP_DECL_TABLECOPY(x)
Definition: type_table.h:69
#define SCIP_DECL_TABLECOLLECT(x)
Definition: type_table.h:133
#define SCIP_DECL_TABLEEXIT(x)
Definition: type_table.h:93